Skip to content

Instantly share code, notes, and snippets.

@lorello
Created November 26, 2019 08:35
Show Gist options
  • Select an option

  • Save lorello/912dbd87970739c680a5a0577423ae03 to your computer and use it in GitHub Desktop.

Select an option

Save lorello/912dbd87970739c680a5a0577423ae03 to your computer and use it in GitHub Desktop.
Simple Log function in Bash
# a simple log function in bash
# usage:
# log "my info message"
# log "my debug message" debug
log_level=info
# uncomment next line to rise up log level
#log_level=debug
log() {
local msg=$1
local level=${2:-info}
if [[ $level == debug ]] && [[ $log_level != debug ]]; then
return 0
fi
now=$(date --rfc-3339=seconds)
echo "$now [$level] $msg" >> /dev/stderr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment