Created
December 16, 2020 23:40
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This shows under the drupal watchdog stream.