Colourful Bash Logging

(, de)

Poor man’s logging implementation for bash scripts:

YELLOW=$'\e[33m'
BLUE=$'\e[34m'
RED=$'\e[31m'
NC=$'\e[0m'

isodate() {
  date "+%Y-%m-%d %H:%M:%S"
}

log_error() {
  echo "$RED$(isodate) [ERROR] $*$NC"
}

log_warn() {
  echo "$YELLOW$(isodate) [WARN] $*$NC"
}

log_info() {
  echo "$BLUE$(isodate) [INFO] $*$NC"
}

log_debug() {
  echo "$(isodate) [DEBUG] $*"
}
log_error "foo bar"
log_warn "foo bar"
log_info "foo bar"
log_debug "foo bar"

Bash logging output