On this page:
with-logging-to-port
with-intercepted-logging
Version: 5.1.3

19 Logging

Vincent St-Amour <stamourv@racket-lang.org>

 (require unstable/logging)

This module provides tools for logging.

This library is unstable; compatibility will not be maintained. See Unstable: May Change Without Warning for more information.

(with-logging-to-port port    
  proc    
  [#:level level])  any
  port : output-port?
  proc : (-> any)
  level : (or/c 'fatal 'error 'warning 'info 'debug) = 'info
Runs proc, outputting any logging of level level or higher to port. Returns whatever proc returns.

Example:

> (let ([my-log (open-output-string)])
    (with-logging-to-port my-log
      (lambda ()
        (log-warning "Warning World!")
        (+ 2 2))
      #:level 'warning)
    (get-output-string my-log))

"Warning World!\n"

(with-intercepted-logging interceptor    
  proc    
  [#:level level])  any
  interceptor : 
(-> (vector/c
      (or/c 'fatal 'error 'warning 'info 'debug)
      string?
      any/c)
     any)
  proc : (-> any)
  level : (or/c 'fatal 'error 'warning 'info 'debug) = 'info
Runs proc, calling interceptor on any log message of level level or higher. interceptor receives the entire log vectors (see Receiving Logged Events) as arguments. Returns whatever proc returns.

Example:

> (let ([warning-counter 0])
    (with-intercepted-logging
      (lambda (l)
        (when (eq? (vector-ref l 0)
                   'warning)
          (set! warning-counter (add1 warning-counter))))
      (lambda ()
        (log-warning "Warning!")
        (log-warning "Warning again!")
        (+ 2 2))
      #:level 'warning)
    warning-counter)

2