From 244749a3e2eba70b4fa5c720889ec6cb9758b220 Mon Sep 17 00:00:00 2001
From: Peter Taoussanis
Date: Mon, 28 May 2012 20:17:38 +0700
Subject: [PATCH] Added set-config!, set-level! as per suggestion by Jonathan
Fischer Friberg
Signed-off-by: Peter Taoussanis
---
README.md | 31 ++++++++++++++++---------------
src/timbre/core.clj | 3 +++
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index a7d124b..a69cc81 100644
--- a/README.md
+++ b/README.md
@@ -68,29 +68,29 @@ java.lang.Exception: Oh noes
Easily adjust the current logging level:
```clojure
-(swap! timbre/config assoc :current-level :warn)
+(timbre/set-level! :warn)
```
Enable the standard [Postal](https://github.com/drewr/postal)-based email appender:
```clojure
-(swap! timbre/config assoc-in [:shared-appender-config :postal]
- ^{:host "mail.isp.net" :user "jsmith" :pass "sekrat!!1"}
- {:from "me@draines.com" :to "foo@example.com"})
+(timbre/set-config! [:shared-appender-config :postal]
+ ^{:host "mail.isp.net" :user "jsmith" :pass "sekrat!!1"}
+ {:from "me@draines.com" :to "foo@example.com"})
-(swap! timbre/config assoc-in [:appenders :postal :enabled?] true)
+(timbre/set-config! [:appenders :postal :enabled?] true)
```
Rate-limit to one email per message per minute:
```clojure
-(swap! timbre/config assoc-in [:appenders :postal :max-message-per-msecs 60000])
+(timbre/set-config! [:appenders :postal :max-message-per-msecs 60000])
```
And make sure emails are sent asynchronously:
```clojure
-(swap! timbre/config assoc-in [:appenders :postal :async?] true)
+(timbre/set-config! [:appenders :postal :async?] true)
```
### Custom Appenders
@@ -98,14 +98,15 @@ And make sure emails are sent asynchronously:
Writing a custom appender is easy:
```clojure
-(swap! timbre/config assoc-in [:appenders :my-appender]
- {:doc "Hello-world appender"
- :min-level :debug
- :enabled? true
- :async? false
- :max-message-per-msecs nil ; No rate limiting
- :fn (fn [{:keys [message] :as appender-args}]
- (println "Hello world!" message))})
+(timbre/set-config!
+ [:appenders :my-appender]
+ {:doc "Hello-world appender"
+ :min-level :debug
+ :enabled? true
+ :async? false
+ :max-message-per-msecs nil ; No rate limiting
+ :fn (fn [{:keys [message] :as appender-args}]
+ (println "Hello world!" message))})
```
See `(doc timbre/config)` for more information on appenders.
diff --git a/src/timbre/core.clj b/src/timbre/core.clj
index 68babf6..ec34806 100644
--- a/src/timbre/core.clj
+++ b/src/timbre/core.clj
@@ -69,6 +69,9 @@
;; {:from "me@draines.com" :to "foo@example.com"}
:shared-appender-config {:postal nil}}))
+(defn set-config! [ks val] (swap! config assoc-in 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])