forked from webyrd/mediKanren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.rkt
43 lines (38 loc) · 1.2 KB
/
logging.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#lang racket/base
(provide
log-time log-info log-error log-once log-length)
(require
racket/file racket/function racket/list racket/hash
(except-in racket/match ==)
racket/port
racket/pretty
racket/runtime-path
racket/string
json
memoize
racket/format
racket/date
)
(define-syntax log-time
(syntax-rules ()
((_ log-proc log-key label body)
(let-values (((result cpu real gc) (time-apply (lambda () body) '())))
(log-proc log-key label cpu real (car result))
(car result)))))
(define (log-info key message)
(printf "~a ~s ~a ~a\n"
(date->string (seconds->date (current-seconds)) #t)
key
"INFO"
message))
(define (log-error key message)
(printf "~a ~s ~a ~a\n"
(date->string (seconds->date (current-seconds)) #t)
key
"ERROR"
message))
(define/memo* (log-once key label cpu real result)
(log-info key (format "~a [cpu time: ~s real time: ~s]: ~s" label cpu real result)))
(define (log-length key label cpu real results)
(log-info key (format "~a [cpu time: ~s real time: ~s]: ~s"
label cpu real (length (hash-ref results 'results '())))))