From 2560f550a6a218caceaf77ece56e5cbcef35c045 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Thu, 20 May 2021 13:37:59 +0900 Subject: [PATCH] include/log: Don't pass log message through date The log_write() function passes the log message through `date' to prepend the timestamp to it. This causes problems when the message contains format placeholders that are interpreted by date. This commit changes the log_write() function not to pass the log message and prefix through date. --- include/log.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/log.sh b/include/log.sh index 9718ab2..50ae196 100644 --- a/include/log.sh +++ b/include/log.sh @@ -80,18 +80,18 @@ log_write() { if (( $# > 2 )); then for line in "${@:3}"; do - local msg + local timestamp - if ! msg=$(date +"%F %T %z $$ $prefix $line"); then + if ! timestamp=$(date +"%F %T %z"); then echo "Could not get timestamp" 1>&2 return 1 fi - if ! echo "$msg" >> "$__log_file"; then + if ! echo "$timestamp $$ $prefix $line" >> "$__log_file"; then echo "Could not write to $__log_file" 1>&2 fi - echo "$msg" 1>&2 + echo "$timestamp $$ $prefix $line" 1>&2 done else while read -r line; do -- 2.47.3