-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.scm
executable file
·45 lines (32 loc) · 1.12 KB
/
logger.scm
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
44
45
;************** just another logging framework **************
;External Interface
;*************************************************************
;functions
; Returns a procedure: (lambda (level format-str . args) ...)
; (define (get-logger name) ...)
; (define (set-log-level! level) ... )
; (define (set-log-output-stream! out-stream) ... )
;constants: log-levels
(define +debug+ 0)
(define +info+ 1)
(define +warn+ 2)
(define +error+ 3)
(define +fatal+ 4)
;Implementation
;************************************************************
(define *LOG-OUTPUT-STREAM* #t)
(define *LOG-LEVEL* +error+)
; functions
(define (set-log-level! level)
(set! *LOG-LEVEL* level))
(define (set-log-output-stream! out-stream)
(set! *LOG-OUTPUT-STREAM* out-stream))
(define (get-logger name)
(lambda (level format-str . args)
(when (>= level *LOG-LEVEL*)
(apply write-log (cons name (cons format-str args))))))
(define (write-log name format-str . args)
(apply format (cons *LOG-OUTPUT-STREAM* (cons format-str args))))
;Finished
;**************************************************************
(format #t "Logger loaded..~%")