/
log.clj
75 lines (61 loc) · 1.8 KB
/
log.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
(ns clojupyter.log
(:require [clojupyter.kernel.config :as cfg]
[clojure.pprint :as pp]
[clojure.string :as str]
[io.simplect.compose :refer [def- c C p P]]
[taoensso.timbre :as timbre]))
(defmacro debug
[& args]
`(timbre/debug ~@args))
(defmacro info
[& args]
`(timbre/info ~@args))
(defmacro error
[& args]
`(timbre/error ~@args))
(defmacro with-level
[level & body]
`(timbre/with-level ~level ~@body))
(defn ppstr
[v]
(with-out-str
(println)
(println ">>>>>>>")
(pp/pprint v)
(println "<<<<<<<<")))
(defonce ^:private ORG-CONFIG timbre/*config*)
(def- fmt-level
(C name str/upper-case first))
(defn- fmt-origin
[?ns-str ?file]
(str/replace (or ?ns-str ?file "?") #"^clojupyter\." "c8r."))
(defn output-fn
([ data] (output-fn nil data))
([opts data]
(let [{:keys [no-stacktrace?]} opts
{:keys [level ?err msg_ ?ns-str ?file hostname_
timestamp_ ?line]} data]
(str "["
(fmt-level level) " "
(force timestamp_) " "
"Clojupyter" "] "
(str (fmt-origin ?ns-str ?file)
(when ?line (str ":" ?line))) " -- "
(force msg_)
(when-not no-stacktrace?
(when-let [err ?err]
(str "\n" (timbre/stacktrace err opts))))))))
(def CONFIG {:timestamp-opts {:pattern "HH:mm:ss.SSS", :locale :jvm-default, :timezone :utc}
:ns-blacklist ["io.pedestal.*"]
:output-fn output-fn})
(defn- set-clojupyter-config!
[]
(timbre/merge-config! CONFIG))
(defn- reset-config!
[]
(timbre/set-config! ORG-CONFIG))
(defn init!
[]
(set-clojupyter-config!)
(timbre/set-level! (cfg/log-level)))
(init!) ;; avoid spurious debug messages from io.pedestal when loading with midje testing turned on