From 9cb472f7779c9653a9e794dd2b39906fda3c183a Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 24 Mar 2021 08:56:27 +0900 Subject: [PATCH] include/log: Log messages to the logfile AND stderr The log module only writes messages to the log file, which is not enough for scripts that are running in the foreground. This commit changes the log_write() function to log messages to the logfile as well as to stderr. --- include/log.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/log.sh b/include/log.sh index d4e3760..41d2c1c 100644 --- a/include/log.sh +++ b/include/log.sh @@ -64,10 +64,18 @@ log_write() { if (( $# > 2 )); then for line in "${@:3}"; do - if ! date +"%F %T %z $prefix $line" >> "$__log_file"; then - echo "Could not write to $__log_file" 1>&2 + local msg + + if ! msg=$(date +"%F %T %z $prefix $line"); then + echo "Could not get timestamp" 1>&2 return 1 fi + + if ! echo "$msg" >> "$__log_file"; then + echo "Could not write to $__log_file" 1>&2 + fi + + echo "$msg" 1>&2 done else while read -r line; do -- 2.47.3