-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up v2.x appenders to conform to v3.x style #41
Comments
Full example: (ns taoensso.timbre.appenders.postal
"Email appender. Requires https://github.com/drewr/postal."
{:author "Peter Taoussanis"}
(:require [clojure.string :as str]
[postal.core :as postal]
[taoensso.timbre :as timbre]))
(defn- str-trunc [^String s max-len]
(if (<= (.length s) max-len) s
(.substring s 0 max-len)))
(comment (str-trunc "Hello this is a long string" 5))
(defn make-postal-appender
"Returns a Postal email appender.
A Postal config map can be provided here as an argument, or as a :postal key
in :shared-appender-config.
(make-postal-appender {:enabled? true}
{:postal-config
^{:host \"mail.isp.net\" :user \"jsmith\" :pass \"sekrat!!1\"}
{:from \"Bob's logger <me@draines.com>\" :to \"foo@example.com\"}})"
[& [appender-opts {:keys [postal-config subject-len]
:or {subject-len 150}}]]
(let [default-appender-opts
{:enabled? true
:min-level :error
:async? true ; Slow!
:rate-limit [5 (* 1000 60 2)] ; 5 calls / 2 mins
:fmt-output-opts {:nofonts? true} ; Disable ANSI escaped stuff
}]
(merge default-appender-opts appender-opts
{:fn
(fn [{:keys [ap-config output]}]
(when-let [postal-config (or postal-config (:postal ap-config))]
(postal/send-message
(assoc postal-config
:subject (-> (str output)
(str/trim)
(str-trunc subject-len)
(str/replace #"\s+" " "))
:body output))))})))
(def postal-appender "DEPRECATED: Use `make-postal-appender` instead."
(make-postal-appender)) |
Hmm... I might be missing something here. I'm just evaluating timbre and here's a point I don't get. The example usage of What am I missing? Thanks! |
Hi Fernando, In the example here, The extra config map is an optional, private config map for So appender constructors will usually take a single arg ( That sounds more complicated than it is :-)
The 2nd argument isn't ignored, it's destructured to get So:
Does that make sense / help? Cheers! :-) |
Thanks a lot for the response, Peter. My mistake: I was actually looking at |
Hi Fernando, sorry for the delay following-up - was on vacation!
Sure, gotcha. So sometimes an unused arg will still be given a name just to clarify that it is there/available, even if it's unused. I'll actually usually use a Does that help / make sense? |
Good for you! Here's the issue... I want to configure the rolling-appender's (make-rolling-appender {:enabled? true}
{:path \"log/app.log\"
:pattern :daily})
... ... however, the implementation ignores it. And that's my problem. Took me awhile to find out why it wasn't working. The way I'm configuring it now is by setting the Am I clearer now? Thanks again. |
Ahh, that appears to be a bug in the rolling appender. I can't recall now who the original author is, but this should be a relatively small/quick change if you felt making a PR? |
Did anyone ever fix this? Was wondering why my rolling appender wasn't working :) Update guessing not, so I opened a PR. |
The v3.0.0 Carmine and Postal appenders have adopted a new style that I'd like to see carried over into 3rd party appenders. Basically each appender ns now exposes a
make-<X>-appender
(ƒ [& [appender-opts make-opts]])
that'll return a ready-to-use Timbre appender.appender-opts
are any general opts like{:enabled? true :min-level :error}
. The appender creator fn will supply defaults, override-able withappender-opts
.make-opts
are any opts specific to this appender - e.g. database connections, special formatting options, etc. The options exposed here will be up to the appender author.If anyone feels like helping out (esp. if you're the author of a v2.x appender), please consider a PR to bring the old appenders in line with the new, more flexible style. You can see the
taoensso.timbre.appenders.postal
ortaoensso.timbre.appenders.carmine
namespaces for examples.Thanks a ton! Feel free to ping me with questions, etc.
The text was updated successfully, but these errors were encountered: