# In-out-logged module updated to show results

**URL:** <https://racket.discourse.group/t/in-out-logged-module-updated-to-show-results/563>\
**Category:** Show & Tell\
**Tags:** module\
**Created:** [January 12, 2022, 11:00pm UTC](https://racket.discourse.group/t/in-out-logged-module-updated-to-show-results/563 "2022-01-12T23:00:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dstorrs](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dstorrs](https://racket.discourse.group/u/dstorrs)\
**Post date:** [January 12, 2022, 11:00pm UTC](https://racket.discourse.group/t/in-out-logged-module-updated-to-show-results/563/1 "2022-01-12T23:00:49Z")

</div>

A common pattern I encounter when writing code is that I want to know when control enters a function, what it does while it's there, when it exits, and what it returns. I got tired of writing all this manually, so I created the in-out-logged module. Demonstration below.

```scheme
#lang racket

(require in-out-logged)

(define-logger foo)

(define (on-complete op . args)
  (log-foo-debug "message from inside on-complete")
  (apply op args))

> (in/out-logged ("on-complete, default version")
	       (on-complete + 1 2 3))

; spits out the following logging (formatted as per racket-mode)
[debug] entering on-complete, default version.
[debug] foo: message from inside on-complete
[debug] leaving on-complete, default version.

; in/out messages to a specified logger at specified level, show results and key/value args    
> (in/out-logged ("on-complete with arguments and results"
                 #:to foo-logger
                 #:at 'info
                 #:results (result)
                 "time" (current-seconds)
                 "thread-id" 17)
     (on-complete + 1 2 3))

; spits out the following logging (formatted as per racket-mode)
[info] foo: entering on-complete with arguments and results.
        time 1642026438
	    thread-id 17
[debug] foo: message from inside on-complete
[info] foo: leaving on-complete with arguments and results. results: (values 6)
        time 1642026438
        thread-id 17

; in/out messages to (current-logger) at 'debug, don't show results, format args by hand         
> (in/out-logged ("explicit argument formatting"
                #:with "~a, ~a, and ~a."
                "foo" "bar" "baz")
    (on-complete + 1 2 3))

; spits out the following logging (formatted as per racket-mode)
[debug] entering explicit argument formatting. foo, bar, and baz.
[debug] message from inside on-complete
[debug] leaving explicit argument formatting. foo, bar, and baz.

; no problem with multiple value return
(in/out-logged ("multiple value return" #:to foo-logger #:results (x y z))
  (values 1 2 3))

; spits out the following logging (formatted as per racket-mode)
[debug] foo: entering multiple value return.
[debug] foo: leaving multiple value return. results: (values 1 2 3)

```
