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