Commit af9244f45f17590ff2ad739955fbbc7847ca59dd

Thomas de Grivel 2023-02-13T10:29:20

shpkg_start_logging

diff --git a/bin/shpkg b/bin/shpkg
index b4aa277..a43680d 100755
--- a/bin/shpkg
+++ b/bin/shpkg
@@ -136,13 +136,11 @@ redirect_err () {
 }
 
 log () {
-    SHPKG_LOG_DIR="$(dirname "${SHPKG_LOG}")"
-    {
-        if ! [ -d "${SHPKG_LOG_DIR}" ]; then
-            verbose 1 mkdir -p "${SHPKG_LOG_DIR}"
-        fi
-        redirect_err "$@"
-    } | tee "${SHPKG_LOG}"
+    if ! [ -d "${SHPKG_LOG_DIR}" ]; then
+        verbose 1 mkdir -p "${SHPKG_LOG_DIR}"
+    fi
+    shpkg_start_logging
+    redirect_err "$@" | tee -a "${SHPKG_LOG}"
 }
 
 log main "$@"
diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index 11a984b..f5ea192 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -12,13 +12,12 @@ SHPKG_DIR="${SHPKG_DIR:-${HOME}/shpkg}"
 SHPKG_ETC_DIR="${SHPKG_DIR}/etc/shpkg"
 SHPKG_INCLUDE_DIR="${SHPKG_DIR}/include"
 SHPKG_LIB_DIR="${SHPKG_DIR}/lib"
+SHPKG_LOG_DIR="${SHPKG_DIR}/var/log/shpkg"
 SHPKG_SHARE_DIR="${SHPKG_DIR}/share/shpkg"
 SHPKG_SRC_DIR="${SHPKG_DIR}/src"
 SHPKG_VAR_DB_DIR="${SHPKG_DIR}/var/db/shpkg"
-SHPKG_LOG_DIR="${SHPKG_DIR}/var/log/shpkg"
 
 SHPKG_PREFIX="${SHPKG_DIR}"
-SHPKG_LOG="${SHPKG_LOG_DIR}/shpkg_${SHPKG_DATE}.log"
 
 # Console output
 
@@ -57,6 +56,13 @@ err () {
     verbose 1 exit "$R"
 }
 
+# Logging
+
+shpkg_start_logging () {
+    SHPKG_LOG="${SHPKG_LOG_DIR}/shpkg_${SHPKG_DATE}_$$.log"
+    verbose -n 2 "shpkg_start_logging: see log with less -R ${SHPKG_LOG}" | tee "${SHPKG_LOG}"
+}
+
 # C compiler
 
 if [ "x${CC}" = "x" ]; then