-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.clj
44 lines (32 loc) · 908 Bytes
/
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
(ns certifiable.log
(:require [clojure.string :as string]))
(def log-levels {:all 0
:debug 1
:info 2
:warn 3
:error 4
:fatal 5
:off 6})
(def ^:dynamic *log-level* :info)
(def ^:dynamic *log-fn* println)
(defn level-tag [level]
(str "[Certifiable"
(when (#{:debug :warn :error :fatal} level)
(str ":" (string/upper-case (name level))))
"]"))
(defn log* [level & args]
(when-let [v (log-levels level)]
(when (<= (log-levels *log-level*) v)
(apply *log-fn* (level-tag level)
(map str args))
nil)))
(defn info [& args]
(apply log* :info args))
(defn debug [& args]
(apply log* :debug args))
(defn warn [& args]
(apply log* :warn args))
(defn error [& args]
(apply log* :error args))
(defn fatal [& args]
(apply log* :fatal args))