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.
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