myshellconfig/bin/testlog

48 lines
1.3 KiB
Text
Raw Permalink Normal View History

2020-10-25 11:24:45 +01:00
#!/bin/bash
LANG=C
2022-09-14 14:43:45 +02:00
for f in logerror logwarning loginfo logdebug logtrace ENTRY EXIT SCRIPTENTRY SCRIPTEXIT; do
2020-10-25 11:24:45 +01:00
if LANG=C type -t $f 2> /dev/null| grep -q 'function'; then
:
else
fx=${f//log/}
#echo "create function $f for $fx"
eval "$f () { \
local loglevels; \
declare -a loglevels; \
case $fx in
error)
loglevels=()
;;
warn)
loglevels=(\"ERROR\")
;;
info)
loglevels=(\"ERROR\" \"WARN\" )
;;
debug)
loglevels=( \"ERROR\" \"WARN\" \"INFO\" )
;;
trace|ENTRY|EXIT|SCRIPTENTRY|SCRIPTEXIT)
loglevels=( \"ERROR\" \"WARN\" \"INFO\" \"DEBUG\" )
;;
esac
if [[ ! \${loglevels[*]} =~ \"\${LOGLEVEL-\${LOGLEVEL_DEFAULT}}\" ]];then \
echo "\$@" >&2
fi; \
}"
unset fx
fi
done
unset f
logerror "ich bin ein error"
2022-09-14 14:43:45 +02:00
logwarning "ich bin eine warnung"
2020-10-25 11:24:45 +01:00
loginfo "ich bin eine info"
logdebug "ich bin eine debuginfo"
logtrace "ich rede zuviel"
ENTRY "ich starte eine function"
EXIT "ich beende eine function"
SCRIPTENTRY "ich starte ein script"
SCRIPTEXIT "ich beende ein script"