-
Notifications
You must be signed in to change notification settings - Fork 3
/
logger.lisp
54 lines (48 loc) · 1.71 KB
/
logger.lisp
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
46
47
48
49
50
51
52
53
54
(uiop:define-package #:cl-fluent-logger/logger
(:use #:cl)
(:shadow #:log
#:trace
#:debug
#:warn
#:error)
(:import-from #:cl-fluent-logger/logger/level
#:with-log-level)
(:use-reexport #:cl-fluent-logger/logger/base
#:cl-fluent-logger/logger/fluent
#:cl-fluent-logger/logger/text
#:cl-fluent-logger/logger/null
#:cl-fluent-logger/logger/level
#:cl-fluent-logger/logger/broadcast)
(:import-from #:alexandria
#:hash-table-alist)
(:export #:*logger*
#:with-logger
#:log
#:trace
#:debug
#:info
#:warn
#:error
#:fatal))
(in-package #:cl-fluent-logger/logger)
(defvar *logger*
(make-instance 'null-logger))
(defmacro with-logger (logger &body body)
`(let ((*logger* ,logger))
,@body))
(declaim (inline log post))
(defun log (tag data)
(post *logger* tag data))
(declaim (ftype function trace debug info warn error fatal))
#.`(progn
,@(loop for level in '(trace debug info warn error fatal)
collect `(defun ,level (tag data)
(with-log-level ,(intern (symbol-name level) :keyword)
(log tag
(cons '("level" . ,(intern (symbol-name level) :keyword))
(typecase data
(hash-table (hash-table-alist data))
(cons data)
(otherwise
`(("payload" . ,data))))))))))
(declaim (notinline log post))