]> git.plutz.net Git - cgilite/blob - logging.sh
f10ea4c43283842e4e188ec0f0306672caf9f96e
[cgilite] / logging.sh
1 #!/bin/sh
2
3 # LOGLEVEL 1: Crash condition
4 # LOGLEVEL 2: Unexpected condition
5 # LOGLEVEL 3: Failed action (i.e. due to config error)
6 # LOGLEVEL 4: Debug
7
8 [ -n "$include_logging" ] && return 0
9 include_logging="$0"
10
11 LOGLEVEL="${LOGLEVEL:-3}"
12 LOGFILE="${LOGFILE:-/dev/stderr}"
13
14 logmsg(){
15   if [ "${1:-3}" -le "$LOGLEVEL" ]; then
16     [ "$#" -gt 1 ] \
17     && printf %s\\n "$*" >>"${LOGFILE}" \
18     || tee -a "${LOGFILE}"
19   fi
20 }
21
22
23 die(){
24   [ "$#" -gt 0 ] && logmsg 1 "$@"
25   exit 1
26 }
27 panic(){ logmsg 2 "$@"; }
28 error(){ logmsg 3 "$@"; }
29 debug(){ logmsg 4 "$@"; }