Created
April 19, 2016 14:38
-
-
Save Ham5ter/7c35113e884ce701369f8533b4b96ace to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# | |
# Logging to local Syslog Example for Bash Scripts | |
# | |
# Author: ham5ter@ham5ter.de | |
# | |
# todo: Make using a external syslog server an easy to configure Option | |
# | |
VERBOSE_OUTPUT=true | |
ACTIVATE_LOGGING=true | |
LOG_TO_FILE=true | |
LOGGER_TAG=$(basename $0) | |
LOGFILE="/tmp/logfile.log" | |
log_msg(){ | |
if [ "$ACTIVATE_LOGGING" = true ]; then | |
if [ "$VERBOSE_OUTPUT" = true ]; then | |
echo "$1" | |
fi | |
if [ "$LOG_TO_FILE" = true ]; then | |
logger -s -t $LOGGER_TAG -i "$1" 2>> $LOGFILE | |
else | |
logger -t $LOGGER_TAG -i "$1" | |
fi | |
fi | |
} | |
main(){ | |
log_msg "this is a test Message" | |
} | |
main | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment