Skip to content

Instantly share code, notes, and snippets.

@arobb
Created July 24, 2020 17:29
Show Gist options
  • Save arobb/c3f4c806a9d7cef4277e24b10e776734 to your computer and use it in GitHub Desktop.
Save arobb/c3f4c806a9d7cef4277e24b10e776734 to your computer and use it in GitHub Desktop.
Simple Bash function to manage output logging
# Logging
OFF=0
FATAL=100
ERROR=200
WARN=300
INFO=400
DEBUG=500
TRACE=600
ALL=1000000
function log() {
level="$1"
# Skip if we don't want to see this kind of message
if [ "${!level}" -gt "${!LOG_LEVEL}" ]; then
return 0
fi
format="%s"
print_arr=("$level")
for i in "${@:2}"; do
format="$format\t%s"
print_arr+=("$i")
done
printf "$format\n" "${print_arr[@]}" 1>&2
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment