fixed logging output

This commit is contained in:
pyr0ball 2023-01-11 10:20:52 -08:00
parent d388db110f
commit 83c236c74c

View file

@ -2,7 +2,7 @@
# pyr0ball script functions library # pyr0ball script functions library
# Initial Vars # Initial Vars
functionsrev=1.1.1 functionsrev=1.1.2
scriptname="${0##*/}" scriptname="${0##*/}"
rundir="${0%/*}" rundir="${0%/*}"
rundir_absolute=$(cd `dirname $0` && pwd) rundir_absolute=$(cd `dirname $0` && pwd)
@ -495,26 +495,29 @@ boxborder(){
} }
success(){ success(){
_line="$@"
echo -e "\n" echo -e "\n"
boxborder " ${scriptname} ${grn}SUCCESS${dfl}$@" boxborder "${scriptname} ${grn}SUCCESS${dfl} ${_line}"
exit 0 exit 0
} }
warn(){ warn(){
echo -e "\n"
ec=$? ec=$?
_line="$@"
echo -e "\n"
boxtop boxtop
boxline "${lrd}WARNING${lyl}[${ong}code=${red}$ec${lyl}]: $@${dfl}" boxline "${lrd}WARNING${lyl}[${ong}code=${red}$ec${lyl}]: ${_line}${dfl}"
boxbottom boxbottom
} }
fail(){ fail(){
ec=$? ec=$?
echo -e "\n" _line="$@"
boxtop echo -e "\n"
boxline "${lrd}FAILED${lyl}[${ong}code=${red}$ec${lyl}]: $@${dfl}" boxtop
boxbottom boxline "${lrd}FAILED${lyl}[${ong}code=${red}$ec${lyl}]: ${_line}${dfl}"
exit $ec boxbottom
exit $ec
} }
pushd(){ pushd(){
@ -536,7 +539,8 @@ logger(){
#$@ 2>&1 | tee >(ts "[$scriptname][%d-%m-%y %H_%M_%S]" > $logfile) # This version of prepend requires the 'ts' utility from 'moreutils' package #$@ 2>&1 | tee >(ts "[$scriptname][%d-%m-%y %H_%M_%S]" > $logfile) # This version of prepend requires the 'ts' utility from 'moreutils' package
$@ 2>&1 | tee >( $@ 2>&1 | tee >(
while IFS= read -r line; do while IFS= read -r line; do
printf '[%s] %s\n' "${scriptname}][${pretty_date}" "$line" _line=$(echo $line | sed "s,\x1B\[[0-9;]*[mK],,g" | tr -dc '[:print:]')
printf '[%s] %s\n' "${scriptname}][${prettyDate}" "$_line"
done >> $logfile done >> $logfile
) )
} }