-
Notifications
You must be signed in to change notification settings - Fork 0
/
levels.clj
executable file
·197 lines (172 loc) · 5.75 KB
/
levels.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
(ns ont-app.graph-log.levels
{:doc "Macros to condition logging on the operative log level"
}
(:require
[taoensso.timbre :as timbre]
[ont-app.igraph.core :as igraph]
[ont-app.graph-log.core :as glog]
))
^{:vocabulary [:glog/message
]}
(defmacro apply-std-logging-fn-at-level
[val level & args]
`(let []
(if (and (:level timbre/*config*)
(glog/level>= ~level (:level timbre/*config*))
(some (fn [x#] (= x# :glog/message)) (list ~@args)))
~(list (symbol "taoensso.timbre" (name level))
`(apply glog/std-logging-message (list ~@args))))
~val))
^{:vocabulary [:glog/LogGraph
:glog/level
:glog/OFF
]
}
(defmacro apply-log-fn-at-level
"Returns value of `log-fn` on `entry-type` and `args` as appropriate for `level`, else return `default`
Where
<log-fn> is log! or value-log!, to be called only if appropriate for level.
<entry-type> is a keyword naming a type of entry
<args> := [<p> <o>, ...] for log!, [[<p> <o>, ...] <value>] for log-value!
These will only be evaluated if <level> is appropriate
<level> is the level of logging for the log statement, this may be overridden
by the level asserted for <entry-type>
<default> should be the value of <log-fn> if it's log-value!, typically nil
for log!
"
[default log-fn level entry-type & args]
`(let [entry-level# (or (igraph/unique
(@glog/log-graph ~entry-type :glog/level))
~level)
global-level# (or (igraph/unique
(@glog/log-graph :glog/LogGraph :glog/level))
glog/default-log-level)
]
(if (and (not= entry-level# :glog/OFF)
(not= global-level# :glog/OFF)
(glog/level>= entry-level# global-level#))
(apply ~log-fn (reduce conj [~entry-type] (list ~@args)))
~default)))
;; log! per debug level
^{:vocabulary [:glog/TRACE
]
}
(defmacro trace [entry-type & args]
`(let []
(apply-std-logging-fn-at-level nil :trace ~@args)
(apply-log-fn-at-level nil glog/log! :glog/TRACE ~entry-type ~@args)))
^{:vocabulary [:glog/DEBUG
]
}
(defmacro debug [entry-type & args]
`(let []
(apply-std-logging-fn-at-level nil :debug ~@args)
(apply-log-fn-at-level nil glog/log! :glog/DEBUG ~entry-type ~@args)))
^{:vocabulary [:glog/INFO
]
}
(defmacro info [entry-type & args]
`(let []
(apply-std-logging-fn-at-level nil :info ~@args)
(apply-log-fn-at-level nil glog/log! :glog/INFO ~entry-type ~@args)))
^{:vocabulary [:glog/TRACE
]
}
(defmacro warn [entry-type & args]
`(let []
(apply-std-logging-fn-at-level nil :warn ~@args)
(apply-log-fn-at-level nil glog/log! :glog/WARN ~entry-type ~@args)))
^{:vocabulary [:glog/ERROR
]
}
(defmacro error [entry-type & args]
`(let []
(apply-std-logging-fn-at-level nil :error ~@args)
(apply-log-fn-at-level nil glog/log! :glog/ERROR ~entry-type ~@args)))
^{:vocabulary [:glog/FATAL
]
}
(defmacro fatal [entry-type & args]
`(let []
(apply-std-logging-fn-at-level nil :fatal ~@args)
(apply-log-fn-at-level nil glog/log! :glog/FATAL ~entry-type ~@args)))
;; log-value! per log level
^{:vocabulary [:glog/value
:glog/TRACE
]
}
(defmacro value-trace
([entry-type val]
`(value-trace ~entry-type [] ~val))
([entry-type extras val]
(let [args (reduce conj extras [:glog/value val])]
`(let []
(apply-std-logging-fn-at-level nil :trace ~@args)
(apply-log-fn-at-level
~val glog/log-value! :glog/TRACE ~entry-type ~extras ~val)))))
^{:vocabulary [:glog/value
:glog/INFO
]
}
(defmacro value-info
([entry-type val]
`(value-info ~entry-type [] ~val))
([entry-type extras val]
(let [args (reduce conj extras [:glog/value val])
]
`(let []
(apply-std-logging-fn-at-level nil :info ~@args)
(apply-log-fn-at-level
~val glog/log-value! :glog/INFO ~entry-type ~extras ~val)))))
^{:vocabulary [:glog/value
:glog/DEBUG
]
}
(defmacro value-debug
([entry-type val]
`(value-debug ~entry-type [] ~val))
([entry-type extras val]
(let [args (reduce conj extras [:glog/value val])]
`(let []
(apply-std-logging-fn-at-level nil :debug ~@args)
(apply-log-fn-at-level
~val glog/log-value! :glog/DEBUG ~entry-type ~extras ~val)))))
^{:vocabulary [:glog/value
:glog/TRACE
]
}
(defmacro value-warn
([entry-type val]
`(value-warn ~entry-type [] ~val))
([entry-type extras val]
(let [args (reduce conj extras [:glog/value val])]
`(let []
(apply-std-logging-fn-at-level nil :warn ~@args)
(apply-log-fn-at-level
~val glog/log-value! :glog/WARN ~entry-type ~extras ~val)))))
^{:vocabulary [:glog/value
:glog/ERROR
]
}
(defmacro value-error
([entry-type val]
`(value-error ~entry-type [] ~val))
([entry-type extras val]
(let [args (reduce conj extras [:glog/value val])]
`(let []
(apply-std-logging-fn-at-level nil :error ~@args)
(apply-log-fn-at-level
~val glog/log-value! :glog/ERROR ~entry-type ~extras ~val)))))
^{:vocabulary [:glog/value
:glog/FATAL
]
}
(defmacro value-fatal
([entry-type val]
`(value-fatal ~entry-type [] ~val))
([entry-type extras val]
(let [args (reduce conj extras [:glog/value val])]
`(let []
(apply-std-logging-fn-at-level nil :fatal ~@args)
(apply-log-fn-at-level
~val glog/log-value! :glog/FATAL ~entry-type ~extras ~val)))))