Skip to content

Instantly share code, notes, and snippets.

@swichers
Created December 16, 2020 23:40
Show Gist options
  • Save swichers/c0797a97c031415d480999e6a3b4d602 to your computer and use it in GitHub Desktop.
Save swichers/c0797a97c031415d480999e6a3b4d602 to your computer and use it in GitHub Desktop.
Write log lines to the syslog in a way that the Acquia log streamer will show them.
#!/usr/bin/env bash
# Write log lines to the syslog in a way that the Acquia log streamer
# will show them.
WATCHDOG_NAME='Logging Example'
# General logging to syslog.
log() {
(>&2 echo "${1}")
if [[ ! -z "${AH_SITE_NAME}" ]]; then
logger -p local0.info -t ${AH_SITE_NAME} -- "${WATCHDOG_NAME} (info): ${1}"
fi
}
# Log text to STDERR and syslog.
error() {
(>&2 echo "${1}")
if [[ ! -z "${AH_SITE_NAME}" ]]; then
logger -p local0.err -t ${AH_SITE_NAME} -- "${WATCHDOG_NAME} (error): ${1}";
fi
}
# Log an error message and exit the script.
errorexit() { error "${1}"; exit 1; }
log 'This will show in the log stream as info.'
error 'This will show in the log stream as an error.'
errorexit 'This will show in the log stream as an error.'
@swichers
Copy link
Author

This shows under the drupal watchdog stream.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment