Last active
October 25, 2018 22:48
-
-
Save greghendershott/a65bea7753bf69b347a5b28bb9fe3ed3 to your computer and use it in GitHub Desktop.
Make racket/trace output go to a logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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