move needed log filters to make-log-receiver
This commit is contained in:
parent
77d012e69a
commit
b399eb9078
|
@ -22,14 +22,6 @@
|
|||
|
||||
(define global-logger (make-logger))
|
||||
|
||||
(define (default-log-filter level topic)
|
||||
(match topic
|
||||
['optimizer #f]
|
||||
['collapsible-contract-bailout #f]
|
||||
['collapsible-value-bailout #f]
|
||||
['racket/contract #f]
|
||||
[else #t]))
|
||||
|
||||
(define (recv-thd receiver stop-chan)
|
||||
;; iso8601 gang
|
||||
(date-display-format 'iso-8601)
|
||||
|
@ -37,33 +29,31 @@
|
|||
;; formats one log entry to stdout
|
||||
(define (log-one entry)
|
||||
(match-define (vector level msg arg topic) entry)
|
||||
(when (default-log-filter level topic)
|
||||
(define level-str
|
||||
(match level
|
||||
['fatal "FATAL"]
|
||||
['error "ERROR"]
|
||||
['warning "WARN "]
|
||||
['info "INFO "]
|
||||
['debug "DEBUG"]
|
||||
[_ "NONE "]))
|
||||
;; for systemd
|
||||
(define prefix-str
|
||||
(match level
|
||||
['fatal "<2>"]
|
||||
['error "<3>"]
|
||||
['warning "<4>"]
|
||||
['info "<6>"]
|
||||
['debug "<7>"]
|
||||
[_ "<7>"]))
|
||||
(define level-str
|
||||
(match level
|
||||
['fatal "FATAL"]
|
||||
['error "ERROR"]
|
||||
['warning "WARN "]
|
||||
['info "INFO "]
|
||||
['debug "DEBUG"]
|
||||
[_ "NONE "]))
|
||||
;; for systemd
|
||||
(define prefix-str
|
||||
(match level
|
||||
['fatal "<2>"]
|
||||
['error "<3>"]
|
||||
['warning "<4>"]
|
||||
['info "<6>"]
|
||||
['debug "<7>"]
|
||||
[_ "<7>"]))
|
||||
|
||||
;; in UTC
|
||||
(define time-str
|
||||
(date->string (seconds->date (* 0.001 (current-inexact-milliseconds)) #f) #t))
|
||||
;; prefix each line of the log entry with the metadata
|
||||
(define msg-lines (string-split msg "\n"))
|
||||
(for ([line (in-list msg-lines)])
|
||||
(printf "~a[~aZ] [~a] ~a\n" prefix-str time-str level-str line)
|
||||
(flush-output (current-output-port)))))
|
||||
;; in UTC
|
||||
(define time-str (date->string (seconds->date (* 0.001 (current-inexact-milliseconds)) #f) #t))
|
||||
;; prefix each line of the log entry with the metadata
|
||||
(define msg-lines (string-split msg "\n"))
|
||||
(for ([line (in-list msg-lines)])
|
||||
(printf "~a[~aZ] [~a] ~a\n" prefix-str time-str level-str line)
|
||||
(flush-output (current-output-port))))
|
||||
|
||||
;; process log entries until told to stop
|
||||
;; this uses the same technique as with-intercepted-logging
|
||||
|
@ -84,7 +74,20 @@
|
|||
;; install the logging system
|
||||
;; call as early as possible in the application
|
||||
(define (install-logging! [level 'debug])
|
||||
(define recv (make-log-receiver global-logger level))
|
||||
(define recv
|
||||
(make-log-receiver
|
||||
global-logger
|
||||
;; set of default filters
|
||||
'info 'optimizer
|
||||
'warning 'collapsible-contract-bailout
|
||||
'warning 'collapsible-value-bailout
|
||||
'warning 'racket/contract
|
||||
'warning 'cm-accomplice
|
||||
'info 'GC
|
||||
'warning 'module-prefetch
|
||||
'info 'sequence-specialization
|
||||
;; default level
|
||||
level #f))
|
||||
(define stop-chan (make-channel))
|
||||
(define logger-thd (thread (lambda () (recv-thd recv stop-chan))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue