Skip to content

Instantly share code, notes, and snippets.

@DarrenN
Forked from greghendershott/trace.log-rkt
Created September 1, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarrenN/513ae39807a580348a7b7192ab6efbeb to your computer and use it in GitHub Desktop.
Save DarrenN/513ae39807a580348a7b7192ab6efbeb to your computer and use it in GitHub Desktop.
Make racket/trace output go to a logger
#lang racket/base
(require racket/format
racket/list
racket/match
racket/trace)
(provide (all-defined-out)
(all-from-out racket/trace))
;; 1. `require` this. Now racket/trace will output using
;; log-trace-debug.
;;
;; 2. Add `(trace func1 func2 ...)` at the bottom of your file.
;;
;; 3. In racket-mode or DrRacket, set the logger to show 'debug level
;; for the "trace" logger (a.k.a. topic).
(define-logger trace)
(define (trace-notify s)
(log-trace-debug "~a" s))
(define top-left #\u250c)
(define bot-left #\u2514)
(define horz #\u2500)
(define vert #\u2502)
(define rarrow #\u25b6)
(define (trace-print-args name args kws kw-vals level)
(printf
"~a~a~s\n" ;add \n because it will be stripped for trace-notify
(make-string level vert)
top-left
`(,name ,@args ,@(append-map list kws kw-vals))))
(define (trace-print-results name results level)
(printf
"~a~a~a~a~a\n" ;add \n because it will be stripped for trace-notify
(make-string level vert)
bot-left
horz
rarrow
(match results
[(list) "** no values **"]
[(list v) (~v v)]
[vs (~v (cons 'values vs))])))
(current-trace-notify trace-notify)
(current-trace-print-args trace-print-args)
(current-trace-print-results trace-print-results)
(module+ test
(define (f x) (if (zero? x) 0 (add1 (f (sub1 x)))))
(trace f)
(f 3)
(define (g x) (values (f x) (add1 x)))
(trace g)
(g 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment