]> git.corax.cc Git - toolbox/commitdiff
include/log: Remove timestamp and pid from log path
authorMatthias Kruk <m@m10k.eu>
Tue, 6 Apr 2021 23:44:48 +0000 (08:44 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 6 Apr 2021 23:44:48 +0000 (08:44 +0900)
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

index dbac5ea7a2ab78c17f15ebfb4ec14d3200843293..c61b59998f84558c9042c3bffef64e4b50265dad 100644 (file)
@@ -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