guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 02/04: Make date format in the log file configurable.


From: Ludovic Courtès
Subject: [shepherd] 02/04: Make date format in the log file configurable.
Date: Mon, 5 Mar 2018 11:46:24 -0500 (EST)

civodul pushed a commit to branch master
in repository shepherd.

commit 47279dd5953211692fc4fa5bcce2ab457f177da0
Author: Danny Milosavljevic <address@hidden>
Date:   Mon Mar 5 15:56:50 2018 +0100

    Make date format in the log file configurable.
    
    * modules/shepherd/support.scm (default-logfile-date-format): New
    variable.
    * modules/shepherd/comm.scm (%current-logfile-date-format): New
    variable.
    (make-shepherd-output-port): Use it.
    
    Co-authored-by: Ludovic Courtès <address@hidden>
---
 modules/shepherd/comm.scm    | 10 ++++++++--
 modules/shepherd/support.scm |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm
index cdeed4c..dc6e904 100644
--- a/modules/shepherd/comm.scm
+++ b/modules/shepherd/comm.scm
@@ -50,8 +50,10 @@
 
             start-logging
             stop-logging
+            shepherd-output-port
+
             %current-client-socket
-            shepherd-output-port))
+            %current-logfile-date-format))
 
 
 ;; Command for shepherd.
@@ -206,6 +208,10 @@ on service '~a':")
   ;; Socket of the client currently talking to the daemon.
   (make-parameter #f))
 
+(define %current-logfile-date-format
+  ;; 'strftime' format strings for entries in the log file.
+  (make-parameter default-logfile-date-format))
+
 ;; We provide our own output mechanism, because we have certain
 ;; special needs; most importantly, we want to send output to herd
 ;; sometimes.
@@ -234,7 +240,7 @@ on service '~a':")
             (let* ((log (lambda (x)
                           (display x log-output-port)))
                    (init-line (lambda ()
-                                (log (strftime "%Y-%m-%d %H:%M:%S "
+                                (log (strftime (%current-logfile-date-format)
                                                (localtime (current-time)))))))
               (init-line)
               (for-each log (reverse buffer))
diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm
index c67575f..d4b582f 100644
--- a/modules/shepherd/support.scm
+++ b/modules/shepherd/support.scm
@@ -46,6 +46,7 @@
 
             user-homedir
             default-logfile
+            default-logfile-date-format
             default-config-file
             default-socket-dir
             default-socket-file
@@ -311,6 +312,10 @@ TARGET should be a string representing a filepath + name."
       (string-append %localstatedir "/log/shepherd.log")
       (string-append %user-config-dir "/shepherd.log")))
 
+(define default-logfile-date-format
+  ;; 'strftime' format string to prefix each entry in the log.
+  "%Y-%m-%d %H:%M:%S ")
+
 ;; Configuration file.
 (define (default-config-file)
   "Return the default configuration file---either the user's file, or the



reply via email to

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