From 15cb828162605ed1a1623804d7189dda1b70f86b Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 7 Apr 2021 08:44:48 +0900 Subject: [PATCH] include/log: Remove timestamp and pid from log path Having the timestamp and pid in the log path causes a large number of log files to be generated, which makes it difficult to find the correct one. This commit removes the timestamp and pid from the log path, causing all processes with the same name to log to the same file. To distinguish individual processes, the log_write() function will also log the pid of the calling process. --- include/log.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/include/log.sh b/include/log.sh index dbac5ea..c61b599 100644 --- a/include/log.sh +++ b/include/log.sh @@ -2,7 +2,6 @@ __init() { local script_name - local timestamp script_name="${0##*/}" @@ -11,11 +10,6 @@ __init() { return 1 fi - if ! timestamp=$(date +"%Y-%m-%d.%H:%M"); then - echo "Could not make timestamp for the log name" 1>&2 - return 1 - fi - declare -xgri __log_debug=3 declare -xgri __log_info=2 declare -xgri __log_warning=1 @@ -23,7 +17,7 @@ __init() { declare -xgi __log_verbosity="$__log_warning" declare -xgr __log_path="$TOOLBOX_HOME/log" - declare -xgr __log_file="$__log_path/$timestamp.$script_name.$$.log" + declare -xgr __log_file="$__log_path/$script_name.log" if ! mkdir -p "$__log_path"; then return 1 @@ -68,7 +62,7 @@ log_write() { for line in "${@:3}"; do local msg - if ! msg=$(date +"%F %T %z $prefix $line"); then + if ! msg=$(date +"%F %T %z $$ $prefix $line"); then echo "Could not get timestamp" 1>&2 return 1 fi -- 2.47.3