-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
logger.clj
46 lines (37 loc) · 1.37 KB
/
logger.clj
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
(ns lsp4clj.protocols.logger)
(defprotocol ILSPLogger
(setup [this])
(set-log-path [_this log-path])
(-info [this fmeta arg1] [this fmeta arg1 arg2] [this fmeta arg1 arg2 arg3])
(-warn [this fmeta arg1] [this fmeta arg1 arg2] [this fmeta arg1 arg2 arg3])
(-error [this fmeta arg1] [this fmeta arg1 arg2] [this fmeta arg1 arg2 arg3])
(-debug [this fmeta arg1] [this fmeta arg1 arg2] [this fmeta arg1 arg2 arg3]))
(def ^:dynamic *logger*
"Optional logger state to avoid having component available everywhere."
nil)
(defn set-logger! [logger]
(alter-var-root #'*logger* (constantly logger)))
(defmacro info [& args]
(let [fmeta (assoc (meta &form)
:file *file*
:ns-str (str *ns*))]
`(when *logger*
(-info *logger* ~fmeta ~@args))))
(defmacro warn [& args]
(let [fmeta (assoc (meta &form)
:file *file*
:ns-str (str *ns*))]
`(when *logger*
(-warn *logger* ~fmeta ~@args))))
(defmacro error [& args]
(let [fmeta (assoc (meta &form)
:file *file*
:ns-str (str *ns*))]
`(when *logger*
(-error *logger* ~fmeta ~@args))))
(defmacro debug [& args]
(let [fmeta (assoc (meta &form)
:file *file*
:ns-str (str *ns*))]
`(when *logger*
(-debug *logger* ~fmeta ~@args))))