Minor changes

This commit is contained in:
Gerhard Hoffmann 2022-06-03 20:45:52 +02:00
parent 89ef5c69b6
commit a9003c5073

View File

@ -1,19 +1,24 @@
#!/bin/bash
# set -x
if [ ${log_helpers_sourced:-1} = "1" ]; then
readonly log_helpers_sourced=${BASH_SOURCE[0]}
else
printf "$loh_helpers_sourced already sourced\n" &>2
return 0
fi
#if [ ${log_helpers_sourced:-1} = "1" ]; then
# readonly log_helpers_sourced=${BASH_SOURCE[0]}
#else
# return 0
#fi
readonly log_file=/var/log/update_controller.log
if ! [ -f "$log_file" ]; then
touch $log_file
fi
readonly DEBUG=0
readonly INFO=1
readonly WARN=2
readonly CRIT=3
readonly FATAL=4
readonly MAX_DEBUG_LEVEL=5
readonly ERROR=4
readonly FATAL=5
readonly MAX_DEBUG_LEVEL=6
log_level=0
@ -28,17 +33,12 @@ dbg_level () {
}
log() {
local log_file=/var/log/update_controller.log
if [ -f "$log_file" ]; then
touch $log_file
fi
if [[ "$(wc -l < $log_file)" > "100000" ]]; then
if [[ $(("$(wc -l < $log_file)")) -ge $((100000)) ]]; then
# remove first line
sed -e 1d -i $log_file
fi
local msg="$(date +'%Y-%m-%d_%T'): $*"
printf "$msg\n" >&2
printf "log:$msg\n" >&2
printf "$msg\n" >> $log_file
}
@ -66,6 +66,12 @@ log_crit() {
fi
}
log_error() {
if [ $log_level -le $ERROR ]; then
log "ERROR $*"
fi
}
log_fatal() {
if [ $log_level -le $FATAL ]; then
log "FATAL $*"