-
Notifications
You must be signed in to change notification settings - Fork 5
/
platform_log.cljc
66 lines (49 loc) · 1.84 KB
/
platform_log.cljc
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
(ns kabel.platform-log
"Logging for Clojure."
(:require [taoensso.timbre :refer [-log! *config*] :as timbre])
#_(:import [org.slf4j LoggerFactory]))
;; support logging also in clj macroexpansion for cljs
(defn- cljs-env?
"Take the &env from a macro, and tell whether we are expanding into cljs."
[env]
(boolean (:ns env)))
(defmacro if-cljs
"Return then if we are generating cljs code and else for Clojure code.
https://groups.google.com/d/msg/clojurescript/iBY5HaQda4A/w1lAQi9_AwsJ"
[then else]
(if (cljs-env? &env) then else))
#_(defmacro trace [& args]
`(if-cljs
(.trace js/console ~(str *ns*) (pr-str ~@args))
(.trace (LoggerFactory/getLogger ~(str *ns*)) (pr-str ~@args))))
(defmacro trace [& args]
`(timbre/trace ~@args))
#_(defmacro debug [& args]
`(if-cljs
(when (.-debug js/console)
(.debug js/console ~(str *ns*) (pr-str ~@args))
(.log js/console ~(str *ns*) (pr-str ~@args)))
;; do not pr-str values eagerly (at least on the JVM)
(when (.isDebugEnabled (LoggerFactory/getLogger ~(str *ns*)))
(.debug (LoggerFactory/getLogger ~(str *ns*)) (pr-str ~@args)))))
(defmacro debug [& args]
`(timbre/debug ~@args))
#_(defmacro info [& args]
`(if-cljs
(.info js/console ~(str *ns*) (pr-str ~@args))
(when (.isInfoEnabled (LoggerFactory/getLogger ~(str *ns*)))
(.info (LoggerFactory/getLogger ~(str *ns*)) (pr-str ~@args)))))
(defmacro info [& args]
`(timbre/info ~@args))
#_(defmacro warn [& args]
`(if-cljs
(.warn js/console ~(str *ns*) (pr-str ~@args))
(.warn (LoggerFactory/getLogger ~(str *ns*)) (pr-str ~@args))))
(defmacro warn [& args]
`(timbre/warn ~@args))
#_(defmacro error [& args]
`(if-cljs
(.error js/console ~(str *ns*) (pr-str ~@args))
(.error (LoggerFactory/getLogger ~(str *ns*)) (pr-str ~@args))))
(defmacro error [& args]
`(timbre/error ~@args))