diff --git a/src/lib/common.sh b/src/lib/common.sh index 89c4e87..0cc8d97 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -34,6 +34,9 @@ log() { # If no arguments AND '0' descriptor is closed, then 'message' will not be set. [[ "$#" == 0 || -t 0 ]] || message="$(cat <&0)" + # Set log date format + [ -n "$log_date_fmt" ] || log_date_fmt='%d/%b/%Y:%H:%M:%S %z' + while (( "$#" )); do case "$1" in -p|--print) print=1; shift;; @@ -45,6 +48,6 @@ log() { [[ "$print" == 1 ]] && echo "$message" while read line; do - printf '[%s] [%s] %s\n' "$(date +'%d %b %Y %H:%M:%S %z')" "$0" "$line" >> "$log_file" + printf '[%s] [%s] %s\n' "$(date +"$log_date_fmt")" "$0" "$line" >> "$log_file" done <<< "$(sed -r 's/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g' <<< "$message")" }