Skip to content

Instantly share code, notes, and snippets.

@Ham5ter
Created April 19, 2016 14:38
Show Gist options
  • Save Ham5ter/7c35113e884ce701369f8533b4b96ace to your computer and use it in GitHub Desktop.
Save Ham5ter/7c35113e884ce701369f8533b4b96ace to your computer and use it in GitHub Desktop.
#!/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