added check to logfile
This commit is contained in:
parent
14e4a6139d
commit
86c10738ce
1 changed files with 17 additions and 13 deletions
30
functions
30
functions
|
|
@ -410,20 +410,24 @@ run-and-log(){
|
||||||
}
|
}
|
||||||
|
|
||||||
logger(){
|
logger(){
|
||||||
if [ ! -f $logfile ] ; then
|
if [ ! -z $logfile ] ; then
|
||||||
run mkdir -p ${rundir%/*}
|
if [ ! -f $logfile ] ; then
|
||||||
touch $logfile
|
run mkdir -p ${rundir%/*}
|
||||||
|
touch $logfile
|
||||||
|
fi
|
||||||
|
$@ 2>&1 | tee >(
|
||||||
|
while IFS= read -r line; do
|
||||||
|
# strip any escaped strings for logging output
|
||||||
|
_line=$(echo $line | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tr -dc '[:print:]')
|
||||||
|
# only print out non-empty lines to log
|
||||||
|
if [[ "$_line" != "" ]] ; then
|
||||||
|
printf '[%s] %s\n' "${scriptname}][${pretty_date}" "$_line"
|
||||||
|
fi
|
||||||
|
done >> $logfile
|
||||||
|
)
|
||||||
|
else
|
||||||
|
$@
|
||||||
fi
|
fi
|
||||||
$@ 2>&1 | tee >(
|
|
||||||
while IFS= read -r line; do
|
|
||||||
# strip any escaped strings for logging output
|
|
||||||
_line=$(echo $line | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | tr -dc '[:print:]')
|
|
||||||
# only print out non-empty lines to log
|
|
||||||
if [[ "$_line" != "" ]] ; then
|
|
||||||
printf '[%s] %s\n' "${scriptname}][${pretty_date}" "$_line"
|
|
||||||
fi
|
|
||||||
done >> $logfile
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# File handling functions
|
# File handling functions
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue