Back
report (clj)
(source)macro
(report & args)
Examples
timbre
(ns taoensso.timbre-tests
(:require
[clojure.test :as test :refer [deftest testing is]]
[taoensso.encore :as enc]
[taoensso.timbre :as timbre])
(is (= (timbre/set-ns-min-level {:min-level [["a.b" :trace] ["a.c" :debug] ["a.*" :info] ["a.c" :error]]}
"a.c" :report)
{:min-level [["a.c" :report] ["a.b" :trace] ["a.*" :info]]}))
(testing "Levels.appender/basic"
[(is (map? (log-data "ns" :info {:min-level :info} {:min-level :info} [])) "call >= both global and appender")
(is (nil? (log-data "ns" :info {:min-level :report} {:min-level :info} [])) "call < global")
(is (nil? (log-data "ns" :info {:min-level :info} {:min-level :report} [])) "call < appender")])
(deftest namespaces
[(testing "Namespaces/global"
[(is (map? (log-data "ns.1.a" :report {:min-level :trace :ns-filter "ns.1.*"} {} [])))
(is (nil? (log-data "ns.1.b" :report {:min-level :trace :ns-filter "ns.2.*"} {} [])))
(is (nil? (log-data "ns.1.c" :report {:min-level :trace :ns-filter {:allow "ns.1.*" :deny "ns.1.c"}} {} [])) ":deny match")])
(testing "Namespaces/appender"
[(is (map? (log-data "ns.1.a" :report {:min-level :trace :ns-filter "ns.1.*"} {:ns-filter "ns.1.*"} [])) "both global and appender allowed")
(is (nil? (log-data "ns.1.a" :report {:min-level :trace :ns-filter "ns.2.*"} {:ns-filter "ns.1.*"} [])) "global denied")
(is (nil? (log-data "ns.1.a" :report {:min-level :trace :ns-filter "ns.1.*"} {:ns-filter "ns.2.*"} [])) "appender denied")])])
(deftest special-args
[(testing "Special-args/errors"
[(is (nil? (:?err (log-data "ns" :report {} {} ["foo" ]))))
(is (enc/error? (:?err (log-data "ns" :report {} {} [(ex-info "ex" {}) "foo"]))) "First-arg ex -> :?err")
(is (enc/error? (:?err (log-data "ns" :report {} {} [(ex-info "ex" {}) ]))) "First-arg ex -> :?err")
(is (= ["foo"] (:vargs (log-data "ns" :report {} {} [(ex-info "ex" {}) "foo"]))) "First-arg ex dropped from vargs")
(is (= [] (:vargs (log-data "ns" :report {} {} [(ex-info "ex" {}) ]))) "First-arg ex dropped from vargs")])
(testing "Special-args/meta"
[(is (nil? (:?meta (log-data "ns" :report {} {} [ "foo"]))))
(is (nil? (:?meta (log-data "ns" :report {} {} [ {:a :A} "foo"]))))
(is (map? (:?meta (log-data "ns" :report {} {} [^:meta {:a :A} "foo"]))) "First-arg ^:meta {} -> :?meta")
(is (= ["foo"] (:vargs (log-data "ns" :report {} {} [^:meta {:a :A} "foo"]))) "First-arg ^:meta {} dropped from vargs")])])
(deftest output
[(is (= "o1" @(:output_ (log-data "ns" :report {:output-fn (fn [data] "o1")} {} ["a1"]))))
(is (= "o2" @(:output_ (log-data "ns" :report
{:output-fn (fn [data] "o1")} ; Config
{:output-fn (fn [data] "o2")} ; Appender
["a1"])))
(is (= @(:output_ (log-data "ns" :report {:output-fn :output-opts :output-opts {:k :v1}}
{} ["a1"]))
{:k :v1})
(is (= @(:output_ (log-data "ns" :report
{:output-fn :output-opts :output-opts {:k :v1}} ; Config
{ :output-opts {:k :v2}} ; Appender
["a1"]))
{:k :v2})