[module announce] in-out-logged

16 views
Skip to first unread message

David Storrs

unread,
Sep 8, 2021, 4:55:59 PM9/8/21
to Racket Users

Wraps a chunk of code in "entering" and "leaving" log messages, returns the value(s) produced by the code.

Example:

Keyword arguments are all optional. #:to and #:at may appear in either order but #:with must come last if it is present.

(define-logger foo)
(define (on-complete op . args)
    (log-foo-debug "in on-complete")
    (apply op args))

(in/out-logged ("on-complete"
                  #:to foo-logger
                  #:at 'debug ; NB:  This is the default so it could be omitted
                  "time" (current-inexact-milliseconds))
                 (on-complete + 1 2 5))

  (in/out-logged ("values"
                  #:at 'error   ; NB:  Goes to (current-logger) since #:to not given.  Has 'error priority
                  #:with "time is: ~a, username is: ~a." (current-inexact-milliseconds) 'bob)
                 (values 1 2))

Produces:

foo: entering on-complete. args:
time  1631134220582.874
foo: in on-complete
foo: leaving on-complete. args:
time  1631134220582.874
8

entering values. time is: 1631134385090.149, username is: bob.
leaving values. time is: 1631134385090.161, username is: bob.
1
2

With thanks to Martin DeMello and Sorawee Porncharoenwase for suggestions on syntax and functionality.


TODO:  Better formatting of the arguments.






(in/out-logged ("name" #:to foo-logger #:at 'info #:with "args are: ~a ~a" 'arg1 'arg2) code ...)


Reply all
Reply to author
Forward
0 new messages