SummaryRefsLogTreeCommitDiffStats
path: root/src/mcron/base.scm
diff options
context:
space:
mode:
authorDale Mellor <mcron-lsfnyl@rdmp.org>2022-07-07 16:51:31 +0100
committerDale Mellor <mcron-lsfnyl@rdmp.org>2022-07-07 16:51:31 +0100
commite2ecb8045bc9789b109b1e7e0b282269a33ca9fb (patch)
tree1cc499e54f84052838260537cc94ecd46ccd0db6 /src/mcron/base.scm
parenta7a456cd6fab22eab69303a4430edf5501187299 (diff)
downloadmcron-e2ecb8045bc9789b109b1e7e0b282269a33ca9fb.tar.gz
mcron-e2ecb8045bc9789b109b1e7e0b282269a33ca9fb.tar.bz2
mcron-e2ecb8045bc9789b109b1e7e0b282269a33ca9fb.zip
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
Diffstat (limited to 'src/mcron/base.scm')
-rw-r--r--src/mcron/base.scm21
1 files changed, 16 insertions, 5 deletions
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 <job>
(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 <job-data> 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 <job-data> 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