Created
February 8, 2019 09:09
-
-
Save looztra/2fbba0464705b943ca53b21d9aec70ab to your computer and use it in GitHub Desktop.
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
# Borrowed to someone, but I don't remember who it was, sorry :( | |
# Print message $2 with log-level $1 to STDERR, colorized if terminal | |
# log DEBUG "DOCKER_HOST ${DOCKER_HOST}" | |
log() { | |
local level=${1?} | |
shift | |
local code= line="[$(date '+%F %T')] $level: $*" | |
if [ -t 2 ] | |
then | |
case "$level" in | |
INFO) code=36 ;; | |
DEBUG) code=35 ;; | |
WARN) code=33 ;; | |
ERROR) code=31 ;; | |
*) code=37 ;; | |
esac | |
echo -e "\e[${code}m${line}\e[0m" | |
else | |
echo "$line" | |
fi >&2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment