Intercepted Logging
log-interceptor/  c
make-log-interceptor
6.12

Intercepted Logging

 (require make-log-interceptor)
  package: make-log-interceptor

contract

log-interceptor/c

 : 
(parametric->/c [A]
  (->* [(-> A)]
       [#:level (or/c log-level/c #f)
        #:topic (or/c symbol? #false)]
       (values A
               (hash/c log-level/c any/c #:immutable #true #:flat? #true))))
A log interceptor for the logger L is a procedure that executes a thunk and returns two values:
  1. the result of the thunk

  2. a hash of all events logged to L during the thunk, organized by log level.

The optional arguments help filter the log events. If #:level is given, then the returned hash only contains events for the given level and higher levels. If #:topic is given, then the returned hash only contains events with the given topic. The default level is 'info and the default topic is the value of (logger-name L).

procedure

(make-log-interceptor logger)  log-interceptor/c

  logger : logger?
Makes a log interceptor for the given logger.

Examples:
> (define ricardo (gensym 'ricardo))
> (define-logger ricardo)
> (define rick-interceptor (make-log-interceptor ricardo-logger))
> (define (f x)
    (when (eq? x ricardo)
      (log-ricardo-info "f spotted a ricardo"))
    (void))
> (define-values [f-result f-logs]
    (rick-interceptor
      (lambda ()
        (f ricardo)
        (f 'fish)
        (f ricardo))))
> f-logs

'#hasheq((info

          .

          ("ricardo: f spotted a ricardo" "ricardo: f spotted a ricardo"))

         (fatal . ())

         (error . ())

         (debug . ())

         (warning . ()))