X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=logging.sh;fp=logging.sh;h=f10ea4c43283842e4e188ec0f0306672caf9f96e;hp=0000000000000000000000000000000000000000;hb=3b749d034d316a0f5b29683929153a3fbc04e947;hpb=5c24129a2347b2be54fedfec74acc156758e3533 diff --git a/logging.sh b/logging.sh new file mode 100755 index 0000000..f10ea4c --- /dev/null +++ b/logging.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# LOGLEVEL 1: Crash condition +# LOGLEVEL 2: Unexpected condition +# LOGLEVEL 3: Failed action (i.e. due to config error) +# LOGLEVEL 4: Debug + +[ -n "$include_logging" ] && return 0 +include_logging="$0" + +LOGLEVEL="${LOGLEVEL:-3}" +LOGFILE="${LOGFILE:-/dev/stderr}" + +logmsg(){ + if [ "${1:-3}" -le "$LOGLEVEL" ]; then + [ "$#" -gt 1 ] \ + && printf %s\\n "$*" >>"${LOGFILE}" \ + || tee -a "${LOGFILE}" + fi +} + + +die(){ + [ "$#" -gt 0 ] && logmsg 1 "$@" + exit 1 +} +panic(){ logmsg 2 "$@"; } +error(){ logmsg 3 "$@"; } +debug(){ logmsg 4 "$@"; }