civodul pushed a commit to branch wip-syslogd
in repository shepherd.
commit 1a8dede4f30093030bc7fce9fb0b7551fc2bcfa7
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Aug 4 22:54:20 2024 +0200
squash! #:log-files -> #:message-destination
---
modules/shepherd/service/system-log.scm | 39 +++++++++++++++++++--------------
tests/services/system-log.sh | 6 ++---
2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/modules/shepherd/service/system-log.scm
b/modules/shepherd/service/system-log.scm
index 810e980..486c52c 100644
--- a/modules/shepherd/service/system-log.scm
+++ b/modules/shepherd/service/system-log.scm
@@ -225,10 +225,10 @@ and passing them to @var{dispatcher}."
(system-log-priority info))
"-- MARK --" #f))
-(define* (log-dispatcher channel log-files #:key max-silent-time)
+(define* (log-dispatcher channel message-destination #:key max-silent-time)
"Dispatch system log messages received on @var{channel} to log files. Call
-@var{log-files} for each system log message to determine the destination
-file(s)."
+@var{message-destination} for each system log message to determine the
+destination file(s)."
(define kernel-prefix
;; Prefix from messages coming from the "kernel" facility.
(if (string-contains %host-type "linux")
@@ -255,8 +255,8 @@ file(s)."
(newline output)
now))
- (define default-log-files
- (default-log-file-procedure))
+ (define default-message-destination
+ (default-message-destination-procedure))
(lambda ()
(let loop ((ports vlist-null))
@@ -265,11 +265,13 @@ file(s)."
(get-message channel))
((? system-log-message? message)
;; Write MESSAGE to the target file(s).
+ ;; TODO: Support sending to a remote syslog.
(let ((files (or (false-if-exception
- (log-files message)
+ (message-destination message)
#:warning
- (l10n "Uncaught exception in log files procedure:
"))
- (default-log-files message))))
+ (l10n "Uncaught exception \
+in message destination procedure: "))
+ (default-message-destination message))))
(loop (fold (lambda (file ports)
(match (vhash-assoc file ports)
(#f
@@ -305,15 +307,17 @@ file(s)."
ports)
(put-message reply #t))))))
-(define* (spawn-log-dispatcher log-files #:key max-silent-time)
+(define* (spawn-log-dispatcher message-destination #:key max-silent-time)
"Spawn the log dispatcher, responsible for writing system log messages to
-the file(s) returned by @var{log-files} for each message."
+the file(s) returned by @var{message-destination} for each message."
(let ((channel (make-channel)))
- (spawn-fiber (log-dispatcher channel log-files
+ (spawn-fiber (log-dispatcher channel message-destination
#:max-silent-time max-silent-time))
channel))
-(define (default-log-file-procedure)
+(define (default-message-destination-procedure)
+ "Return a procedure that, given a <system-log-message>, returns a good
+default destination to log it to."
(if (zero? (getuid))
(lambda (message)
`(,@(if (member (system-log-message-facility message)
@@ -370,7 +374,8 @@ the file(s) returned by @var{log-files} for each message."
(requirement '())
(kernel-log-file (and (zero? (getuid))
(kernel-log-file)))
- (log-files (default-log-file-procedure))
+ (message-destination
+ (default-message-destination-procedure))
(max-silent-time (* 20 60)))
"Return the system log service (@dfn{syslogd}) with the given
@var{provision} and @var{requirement} (lists of symbols). The service accepts
@@ -378,9 +383,9 @@ connections on @var{sources}, a list of @code{<endpoint>}
objects; optionally
it also reads messages from @code{#:kernel-log-file}, which defaults to
@file{/proc/kmsg} when running as root.
-Log messages are passed to @var{log-files}, a one-argument procedure that must
-return the list of files to write it to. Write a mark to log files when no
-message has been logged for more than @var{max-silent-time} seconds."
+Log messages are passed to @var{message-destination}, a one-argument procedure
+that must return the list of files to write it to. Write a mark to log files
+when no message has been logged for more than @var{max-silent-time} seconds."
(service provision
#:requirement requirement
#:start (lambda ()
@@ -392,7 +397,7 @@ message has been logged for more than @var{max-silent-time}
seconds."
O_NONBLOCK
O_CLOEXEC)))
'())))
- (dispatcher (spawn-log-dispatcher log-files
+ (dispatcher (spawn-log-dispatcher
message-destination
#:max-silent-time
max-silent-time)))
(spawn-fiber
diff --git a/tests/services/system-log.sh b/tests/services/system-log.sh
index 33b50fa..729cf62 100644
--- a/tests/services/system-log.sh
+++ b/tests/services/system-log.sh
@@ -42,8 +42,8 @@ cat > "$conf" <<EOF
(use-modules (shepherd service system-log)
(shepherd endpoints))
-(define (log-files message)
- (pk 'log-files->
+(define (message-destination message)
+ (pk 'message-destination->
(cond ((system-log-message-sender message)
(list "$syslog_remote_file"))
((= (system-log-message-facility message)
@@ -66,7 +66,7 @@ cat > "$conf" <<EOF
(register-services
(list (system-log-service %endpoints
- #:log-files log-files
+ #:message-destination message-destination
#:kernel-log-file "$kmsg")
(service
'(logger)