Make level a keyword argument for with-logging-to-port.

This commit is contained in:
Vincent St-Amour 2011-06-01 15:24:15 -04:00
parent fe161a780c
commit 0538f21274
2 changed files with 10 additions and 10 deletions

View File

@ -11,7 +11,7 @@
;; (log-warning "not ok")
;; If the logging on the last line is executed before the thread listening
;; to the logs sees the stop message, "not ok" will also be sent to port.
(define (with-logging-to-port port level proc)
(define (with-logging-to-port port proc #:level [level 'debug])
(let* ([logger (make-logger #f (current-logger))]
[receiver (make-log-receiver logger level)]
[stop-chan (make-channel)]
@ -41,7 +41,6 @@
(thread-wait t))))
(provide/contract [with-logging-to-port
(-> output-port?
(or/c 'fatal 'error 'warning 'info 'debug)
(-> any)
any)])
(->* (output-port? (-> any))
(#:level (or/c 'fatal 'error 'warning 'info 'debug))
any)])

View File

@ -10,9 +10,9 @@ This module provides tools for logging.
@unstable[@author+email["Vincent St-Amour" "stamourv@racket-lang.org"]]
@defproc[(with-logging-to-port [port output-port?]
[level (or/c 'fatal 'error 'warning 'info 'debug)]
[proc (-> any)])
@defproc[(with-logging-to-port
[port output-port?] [proc (-> any)]
[#:level level (or/c 'fatal 'error 'warning 'info 'debug) 'info])
any]{
Runs @racket[proc], outputting any logging of level @racket[level] or higher to
@ -21,10 +21,11 @@ Runs @racket[proc], outputting any logging of level @racket[level] or higher to
@defexamples[
#:eval (eval/require 'unstable/logging)
(let ([my-log (open-output-string)])
(with-logging-to-port my-log 'warning
(with-logging-to-port my-log
(lambda ()
(log-warning "Warning World!")
(+ 2 2)))
(+ 2 2))
#:level 'warning)
(display (get-output-string my-log)))
]