2017-08-24 20:24:03 +05:30
|
|
|
(library
|
|
|
|
(logging)
|
|
|
|
|
|
|
|
(export with-log-port-thunk
|
|
|
|
with-log-port
|
|
|
|
info
|
|
|
|
warn
|
|
|
|
log-error)
|
|
|
|
|
|
|
|
(import (chezscheme)
|
|
|
|
(fmt fmt)
|
|
|
|
(list-utils)
|
|
|
|
(utils))
|
|
|
|
|
|
|
|
(define log-port (current-error-port))
|
|
|
|
|
|
|
|
(define (with-log-port-thunk port thunk)
|
|
|
|
(fluid-let ((log-port port))
|
|
|
|
(thunk)))
|
|
|
|
|
|
|
|
(define-syntax with-log-port
|
|
|
|
(syntax-rules ()
|
|
|
|
((_ port b1 b2 ...)
|
|
|
|
(with-log-port-thunk port
|
|
|
|
(lambda ()
|
|
|
|
b1 b2 ...)))))
|
|
|
|
|
|
|
|
;; FIXME: include timestamp
|
|
|
|
(define (output-to-log level doc)
|
|
|
|
(fmt log-port
|
|
|
|
(dsp (symbol->string level))
|
|
|
|
(dsp ": ")
|
2017-08-25 14:15:56 +05:30
|
|
|
(apply cat (intersperse (dsp " ") doc))
|
|
|
|
nl))
|
2017-08-24 20:24:03 +05:30
|
|
|
|
|
|
|
(define-syntax define-level
|
|
|
|
(syntax-rules ()
|
|
|
|
((_ sym level) (define (sym . doc) (output-to-log 'level doc)))))
|
|
|
|
|
|
|
|
(define-level info info)
|
|
|
|
(define-level warn warn)
|
|
|
|
(define-level log-error error))
|