Created
May 14, 2019 03:27
-
-
Save utisam/447ed9bef71c6d8cf068d4d2295b1bde to your computer and use it in GitHub Desktop.
Bash Logger
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 | |
[[ -n "${__LOGGER_SH:-}" ]] && return || readonly __LOGGER_SH=1 | |
# Usage: | |
# source ./logger.sh | |
# log_info "message" | |
# 0: DEBUG | |
# 1: INFO | |
# 2: WARN | |
# 3: ERROR | |
declare LOG_LEVEL=${LOG_LEVEL:-1} | |
log_debug() { | |
if (( $LOG_LEVEL <= 0 )); then | |
echo -e "\033[1;40m DEBUG \033[00m $*" 1>&2 | |
fi | |
} | |
log_info() { | |
if (( $LOG_LEVEL <= 1 )); then | |
echo -e "\033[1;44m INFO \033[00m $*" 1>&2 | |
fi | |
} | |
log_warn() { | |
if (( $LOG_LEVEL <= 2 )); then | |
echo -e "\033[1;43m WARN \033[00m $*" 1>&2 | |
fi | |
} | |
log_error() { | |
if (( $LOG_LEVEL <= 3 )); then | |
echo -e "\033[1;41m ERROR \033[00m $*" 1>&2 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment