From e2ecb8045bc9789b109b1e7e0b282269a33ca9fb Mon Sep 17 00:00:00 2001 From: Dale Mellor Date: Thu, 7 Jul 2022 16:51:31 +0100 Subject: Give mcron --log option to turn logging on. This makes the behaviour backwards compatible with all previous uses of mcron. * src/mcron/base.scm: establish %do-logging parameter and act on it * src/mcron/scripts/mcron.scm: set %do-logging according to command line * tests/base.scm: some tests require %do-logging to be set --- src/mcron/base.scm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/mcron/base.scm') diff --git a/src/mcron/base.scm b/src/mcron/base.scm index 6e325f7..79a88a6 100644 --- a/src/mcron/base.scm +++ b/src/mcron/base.scm @@ -45,6 +45,7 @@ display-schedule run-job-loop + %do-logging %date-format %log-format validate-date-format @@ -85,6 +86,8 @@ (user schedule-user set-schedule-user!) ;list of (current schedule-current set-schedule-current!)) ;symbol 'user or 'system +(define %do-logging (make-parameter #f)) + ;; A (srfi srfi-19) format string for the date. It is used to format the ;; timestamp argument. Defaults to the local ISO-8601 date/time format. (define %date-format (make-parameter "~5")) @@ -284,7 +287,8 @@ streams can be read as well as the name of the job." ;; Execute the action. (catch #t (lambda () - (format #t "running...~%") + (if (%do-logging) + (format #t "running...~%")) (flush-all-ports) (let* ((result ((job:action job))) (exit-val/maybe (false-if-exception @@ -292,7 +296,8 @@ streams can be read as well as the name of the job." (when (and exit-val/maybe (not (= 0 exit-val/maybe))) (error "unclean exit status" exit-val/maybe))) - (format #t "completed in ~,3fs~%" (seconds-since start)) + (if (%do-logging) + (format #t "completed in ~,3fs~%" (seconds-since start))) (flush-all-ports) (primitive-exit 0)) (lambda args @@ -354,7 +359,11 @@ associated instance." (cons 'suspended partial-continuation)))) (define (format-line line) - (format #t "~@?" (%log-format) timestamp pid name line)) + (cond ((%do-logging) + (format #t "~@?" (%log-format) timestamp pid name line)) + ((and (string? line) + (not (string-null? line))) + (display line)))) (let loop ((line+delim (read-line*))) (match line+delim @@ -367,8 +376,10 @@ associated instance." (("" . #\cr) ;; A carriage return directly followed a delimiter. Ignore it. (loop (read-line*))) - ((line . _) - (format-line line) + ((line . delim) + (format-line (if (%do-logging) + line + (string-append line (string delim)))) (loop (read-line*))))))) (for-each log-data -- cgit v1.2.3