]> git.corax.cc Git - toolbox/commitdiff
include/log: Don't pass log message through date
authorMatthias Kruk <matthias.kruk@miraclelinux.com>
Thu, 20 May 2021 04:37:59 +0000 (13:37 +0900)
committerMatthias Kruk <matthias.kruk@miraclelinux.com>
Thu, 20 May 2021 04:37:59 +0000 (13:37 +0900)
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

index 9718ab2fca4296636f8a5f8353100a77ff024314..50ae196590f358d391334c18c4431ff5b798b14e 100644 (file)
@@ -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