Permalink
Browse files

Merge branch 'dev'

  • Loading branch information...
2 parents 3b68744 + 7dc339a commit 7ce65ed924527c9da4f7a6cc15cd40025e15acd8 @ptaoussanis committed Jul 1, 2012
Showing with 20 additions and 11 deletions.
  1. +1 −1 README.md
  2. +1 −1 epl-v10.html
  3. +2 −2 project.clj
  4. +16 −7 src/timbre/core.clj
View
@@ -34,7 +34,7 @@ Timbre was built in a day after I finally lost my patience trying to configure L
Depend on Timbre in your `project.clj`:
```clojure
-[com.taoensso/timbre "0.5.1"]
+[com.taoensso/timbre "0.5.2"]
```
and `require` the library:
View
@@ -11,7 +11,7 @@
margin: 0.25in 0.5in 0.25in 0.5in;
tab-interval: 0.5in;
}
- p {
+ p {
margin-left: auto;
margin-top: 0.5em;
margin-bottom: 0.5em;
View
@@ -1,4 +1,4 @@
-(defproject com.taoensso/timbre "0.5.1"
+(defproject com.taoensso/timbre "0.5.2"
:description "Simple, flexible, all-Clojure logging. No XML!"
:url "https://github.com/ptaoussanis/timbre"
:license {:name "Eclipse Public License"}
@@ -16,4 +16,4 @@
:releases {:checksum :fail :update :always}}}
:aliases {"all" ["with-profile" "1.3:1.4:1.5"]}
:min-lein-version "2.0.0"
- :warn-on-reflection true)
+ :warn-on-reflection true)
View
@@ -5,7 +5,7 @@
[clj-stacktrace.repl :as stacktrace]
[postal.core :as postal])
(:import [java.util Date Locale]
- [java.text SimpleDateFormat]))
+ java.text.SimpleDateFormat))
;;;; Default configuration and appenders
@@ -71,20 +71,28 @@
;; {:from "me@draines.com" :to "foo@example.com"}
:postal nil}}))
-(defn set-config! [[k & ks] val] (swap! config assoc-in (cons k ks) val))
-(defn set-level! [level] (set-config! [:current-level] level))
-
;;;; Define and sort logging levels
-(def ^:private ordered-levels [:trace :debug :info :warn :error :fatal])
+(def ^:private ordered-levels [:trace :debug :info :warn :error :fatal :report])
(def ^:private scored-levels (zipmap ordered-levels (range)))
+(defn check-level
+ [x] (when-not (some #{x} ordered-levels)
+ (throw (Exception. (str "Invalid logging level: " x)))))
(def compare-levels
(memoize (fn [x y] (- (scored-levels x) (scored-levels y)))))
(defn sufficient-level?
[level] (>= (compare-levels level (:current-level @config)) 0))
+;;;; Config helpers
+
+(defn set-config! [[k & ks] val] (swap! config assoc-in (cons k ks) val))
+(defn set-level!
+ [level]
+ (check-level level)
+ (set-config! [:current-level] level))
+
;;;; Appender-fn decoration
(defn- make-timestamp-fn
@@ -197,8 +205,9 @@
(defmacro log
"Dispatches given arguments to relevant appender-fns iff logging level is
sufficient."
- {:arglists '([message & more] [throwable message & more])}
+ {:arglists '([level message & more] [level throwable message & more])}
[level & args]
+ (check-level level)
`(let [level# ~level]
(when (sufficient-level? level#)
(when-let [juxt-fn# (@juxt-cache level#)] ; Any relevant appenders?
@@ -226,7 +235,7 @@
(log :trace "arg1"))
(defmacro spy
- "Evaluates expression and logs its form and result. Returns the result.
+ "Evaluates expression and logs its form and result. Always returns the result.
Defaults to :debug logging level."
([expr] `(spy :debug ~expr))
([level expr]

0 comments on commit 7ce65ed

Please sign in to comment.