Created
July 24, 2020 17:29
-
-
Save arobb/c3f4c806a9d7cef4277e24b10e776734 to your computer and use it in GitHub Desktop.
Simple Bash function to manage output logging
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
# 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