Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # place @ start of script for easy modification :)
- # also, you're welcome to override
- : ${LOG_LEVEL:=4} # read function log() @ <logging facility>
- : ${LOG_FD:=2} # 1 = stdout, 2 = stderr
- # ....
- # <logging_facility>
- clr_nc=$'\e[0m'
- clr_red=$'\e[1;31m'
- clr_green=$'\e[1;32m'
- clr_yellow=$'\e[1;33m'
- clr_cyan=$'\e[1;36m'
- log() {
- local L=''
- [ $# -gt 0 ] && L=$1 && shift
- L=${L:-'U'} # 'U' means 'unclassified'
- local c0=${clr_nc} c1=''
- case "$L" in
- E) test ${LOG_LEVEL} -lt 1 && return 0; c1=${clr_red} ;;
- W) test ${LOG_LEVEL} -lt 2 && return 0; c1=${clr_yellow} ;;
- I) test ${LOG_LEVEL} -lt 3 && return 0; c1=${clr_green} ;;
- D) test ${LOG_LEVEL} -lt 4 && return 0; c1=${clr_cyan} ;;
- *) test ${LOG_LEVEL} -lt 4 && return 0; c1=${clr_nc} ;;
- esac
- [ ! -t ${LOG_FD} ] && c0='' && c1=''
- {
- [ $# -gt 0 ] \
- && echo "[${c1}$L${c0}] ${c1}$@${c0}" \
- || sed -re "s#^(.*)\$#[${c1}$L${c0}] ${c1}\\1${c0}#"
- } >&${LOG_FD}
- }
- # </logging_facility>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement