Created
November 26, 2019 08:35
-
-
Save lorello/912dbd87970739c680a5a0577423ae03 to your computer and use it in GitHub Desktop.
Simple Log function in Bash
This file contains hidden or 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
| # 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