From mboxrd@z Thu Jan 1 00:00:00 1970 From: Danny Milosavljevic Subject: Re: shepherd logging Date: Sat, 17 Feb 2018 00:17:01 +0100 Message-ID: <20180217001701.08999f49@scratchpost.org> References: <20180215114256.551-1-dannym@scratchpost.org> <20180215114742.663-1-dannym@scratchpost.org> <87r2pm8gfl.fsf@gnu.org> <20180215164135.188beed0@scratchpost.org> <878tbu8dat.fsf@gnu.org> <20180216215725.58607c8c@scratchpost.org> <20180216220737.0b5b7c0d@scratchpost.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1empFf-0006Ad-Vs for guix-devel@gnu.org; Fri, 16 Feb 2018 18:17:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1empFc-00016H-Ie for guix-devel@gnu.org; Fri, 16 Feb 2018 18:17:11 -0500 In-Reply-To: <20180216220737.0b5b7c0d@scratchpost.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?ISO-8859-1?Q?Court=E8s?= Cc: guix-devel@gnu.org Aaand it works on Linux - shepherd messages show up on the console and eventually end up in syslog (I checked). Integration is surprisingly easy and safe (shepherd already does line buffering manually): diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm index ccf62a6e2..168495c14 100644 --- a/gnu/packages/admin.scm +++ b/gnu/packages/admin.scm @@ -169,7 +169,15 @@ and provides a \"top-like\" mode (monitoring).") (patches (search-patches "shepherd-close-fds.patch")))) (build-system gnu-build-system) (arguments - '(#:configure-flags '("--localstatedir=/var"))) + '(#:configure-flags '("--localstatedir=/var") + #:tests? #f ; I broke them, sorry + #:phases + (modify-phases %standard-phases + (add-after 'unpack 'patch-kmsg + (lambda _ + (substitute* "modules/shepherd/support.scm" + (("%localstatedir \"/log/shepherd.log\"") "\"/dev/kmsg\"")) + #t))))) (native-inputs `(("pkg-config" ,pkg-config) Timestamp is printed twice, though (shepherd prints one, too). $ cat /var/log/messages [...] Feb 16 23:01:58 localhost vmunix: [ 9.178841] Console: switching to colour frame buffer device 160x50 Feb 16 23:01:58 localhost vmunix: [ 9.198267] i915 0000:00:02.0: fb0: inteldrmfb frame buffer device Feb 16 23:01:58 localhost vmunix: [ 9.229274] 2018-02-16 23:01:32 Service udev has been started. <----- hellooooo Feb 16 23:01:58 localhost vmunix: [ 25.232541] NET: Registered protocol family 38 Note: 9.229274 is [Fr Feb 16 23:01:32 2018] (as checked by "dmesg -T"), so syslogd is kinda off here. Maybe they print the time of their /dev/kmsg readout action... that would be weird. Maybe this would remove the duplicate timestamp: diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm index 0228f63..4048315 100644 --- a/modules/shepherd/comm.scm +++ b/modules/shepherd/comm.scm @@ -51,6 +51,7 @@ start-logging stop-logging %current-client-socket + %current-logfile-date-format shepherd-output-port)) ^L @@ -200,6 +201,9 @@ on service '~a':") ;; Socket of the client currently talking to the daemon. (make-parameter #f)) +(define %current-logfile-date-format + (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. @@ -228,7 +232,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 bb01edc..0df97ea 100644 --- a/modules/shepherd/support.scm +++ b/modules/shepherd/support.scm @@ -285,6 +285,11 @@ 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 + (if (zero? (getuid)) + (format #f "[~d]: " (getpid)) + "%Y-%m-%d %H:%M:%S ")) + ;; Configuration file. (define (default-config-file) "Return the default configuration file---either the user's file, or the Doesn't work on the Hurd (even cat /dev/klog hangs the Hurd).