From e4f3d628c0e558a6725a4b6768fd36d86f0fd472 Mon Sep 17 00:00:00 2001 From: alanw Date: Tue, 2 May 2023 12:57:26 -0700 Subject: [PATCH] fixed logs capturing empty lines and escape sequences --- functions | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/functions b/functions index 4805f00..28b7965 100644 --- a/functions +++ b/functions @@ -414,11 +414,14 @@ popdfail(){ } 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 >( while IFS= read -r line; do - _line=$(echo $line | sed "s,\x1B\[[0-9;]*[mK],,g" | tr -dc '[:print:]') - printf '[%s] %s\n' "${scriptname}][${prettyDate}" "$_line" + # 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 ) }