Last active
October 7, 2016 16:05
-
-
Save stephanebruckert/f6440f337a8f81714aecac6b6fba1319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Namespace and dependencies | |
;; | |
(ns sdk-helpers.log | |
;; Clojure | |
(:require [clojure.string :refer [split join]] | |
[clojure.core.match :refer [match]] | |
;; 3rd-party | |
[taoensso.timbre :as timbre])) | |
(defn my-output-fn [data] | |
(clojure.pprint/pprint "my-output-fn was called") | |
(timbre/default-output-fn data)) | |
(def my-config | |
{:output-fn my-output-fn}) | |
(defn init [level] | |
(timbre/merge-config! my-config) | |
(timbre/set-level! level)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns unit.sdk-helpers.log-test | |
(:require [clojure.string :refer [join]] | |
[midje.sweet :refer :all] | |
[sdk-helpers.log :as hlp-log] | |
[taoensso.timbre :as timbre])) | |
(facts "logging functionality" | |
(fact "default config should allow logging from info" | |
(timbre/may-log? :trace) => false | |
(timbre/may-log? :debug) => true | |
(timbre/may-log? :info) => true | |
(timbre/may-log? :warn) => true | |
(timbre/may-log? :error) => true | |
(timbre/may-log? :fatal) => true | |
(timbre/may-log? :report) => true) | |
(fact "can allow all logging levels" | |
(hlp-log/init :trace) | |
(timbre/may-log? :trace) => true | |
(timbre/may-log? :debug) => true | |
(timbre/may-log? :info) => true | |
(timbre/may-log? :warn) => true | |
(timbre/may-log? :error) => true | |
(timbre/may-log? :fatal) => true | |
(timbre/may-log? :report) => true | |
; re-set default level for next tests | |
(hlp-log/init :debug)) | |
(fact "the outputted text" | |
(hlp-log/init :info) | |
(timbre/info "Hello") => nil | |
(provided | |
(hlp-log/my-output-fn anything) => irrelevant :times 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sbruckert in ~/Code/sdk-helpers-cljlib on stephane/timbre [+!$] | |
$ rake test | |
Unit tests | |
-------------------------------------------------------------------------------- | |
lein midje unit.sdk-helpers.* | |
= Namespace unit.sdk-helpers.core-test | |
Checking name generation | |
Checking generates correct stack names | |
= Namespace unit.sdk-helpers.log-test | |
Checking logging functionality | |
Checking default config should allow logging from info | |
Checking can allow all logging levels | |
Checking the outputted text | |
"my-output-fn has been called" | |
16-10-07 15:58:29 MLL1P05380.local INFO [unit.sdk-helpers.log-test:31] - Hello | |
FAIL at (log_test.clj:33) | |
These calls were not made the right number of times: | |
(hlp-log/my-output-fn anything) [expected :times 1, actually called zero times] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment