guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 02/06: logger: File logger keeps an absolute log file name.


From: Ludovic Courtès
Subject: [shepherd] 02/06: logger: File logger keeps an absolute log file name.
Date: Sat, 15 Jun 2024 19:16:12 -0400 (EDT)

civodul pushed a commit to branch devel
in repository shepherd.

commit a37f4f83dcc544d35b2f4e2f78797ac5d03adbe6
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Jun 12 22:27:45 2024 +0200

    logger: File logger keeps an absolute log file name.
    
    * modules/shepherd/logger.scm (service-file-logger): Ensure FILE is
    absolute.
    * tests/services/timer.sh: Adjust accordingly.
---
 modules/shepherd/logger.scm | 32 +++++++++++++++++++-------------
 tests/services/timer.sh     |  2 +-
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/modules/shepherd/logger.scm b/modules/shepherd/logger.scm
index ba09926..f41091e 100644
--- a/modules/shepherd/logger.scm
+++ b/modules/shepherd/logger.scm
@@ -190,19 +190,25 @@ not exist."
                               (history-size (default-log-history-size)))
   "Return a thunk meant to run as a fiber that reads from @var{input} and logs 
it
 to @var{file}.  Assume it's logging for @var{service}."
-  (catch 'system-error
-    (lambda ()
-      (%service-file-logger channel file input
-                            #:service service
-                            #:history-size history-size))
-    (lambda args
-      (if (= ENOENT (system-error-errno args))
-          (begin
-            (mkdir-p (dirname file))
-            (%service-file-logger channel file input
-                                  #:service service
-                                  #:history-size history-size))
-          (apply throw args)))))
+  ;; Keep FILE as an absolute file name.  This is necessary for instance so
+  ;; that the 'log-rotation' service passes the right file name to 'gzip' &
+  ;; co., and so that the file name showed in 'herd status SVC' is absolute.
+  (let ((file (if (string-prefix? "/" file)
+                  file
+                  (in-vicinity (getcwd) file))))
+    (catch 'system-error
+      (lambda ()
+        (%service-file-logger channel file input
+                              #:service service
+                              #:history-size history-size))
+      (lambda args
+        (if (= ENOENT (system-error-errno args))
+            (begin
+              (mkdir-p (dirname file))
+              (%service-file-logger channel file input
+                                    #:service service
+                                    #:history-size history-size))
+            (apply throw args))))))
 
 (define* (spawn-service-file-logger file input
                                     #:key
diff --git a/tests/services/timer.sh b/tests/services/timer.sh
index 09f9011..d07a090 100644
--- a/tests/services/timer.sh
+++ b/tests/services/timer.sh
@@ -88,7 +88,7 @@ shepherd_pid="`cat $pid`"
 $herd start timer-with-command
 sleep 2
 grep "Hi from " "$service_log"
-$herd status timer-with-command | grep "Log file: $service_log"
+$herd status timer-with-command | grep "Log file: $PWD/$service_log"
 $herd status timer-with-command | grep "Hi from " # recent messages
 $herd status timer-with-command | grep "exited successfully" # recent runs
 $herd stop timer-with-command



reply via email to

[Prev in Thread] Current Thread [Next in Thread]