From: Matthias Kruk Date: Tue, 23 Mar 2021 23:56:27 +0000 (+0900) Subject: include/log: Log messages to the logfile AND stderr X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=9cb472f7779c9653a9e794dd2b39906fda3c183a;p=toolbox 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. --- 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