Closed vemv closed 4 months ago
I believe if a middleware returns nil
, then nothing is printed. See Architecture on the wiki, step 4: "Pass the data map through any middleware fns: (fn [data]) -> ?data. These may transform the data. If returned data is nil, end here and noop."
As an example, I have this in a test fixture, to not do any logging when testing our authorization endpoints:
(defn silence-auth-logs
[f]
(timbre/with-config
(update timbre/*config* :middleware conj
(fn [data]
(when-not (str/includes? (or (first (:vargs data)) "") "Incorrect authorization")
data)))
(f)))
But what if I have N appenders and I just want to drop it for Sentry?
That's the essence of my question.
Oh, my apologies. I missed that you meant a single appender of many. I'm not sure that answer.
Just have my hands a bit full atm, so apologies for the brief answer-
Timbre's appenders are ultimately just normal Clojure functions, so you can easily wrap them with whatever behaviour you like.
I.e. you can basically implement appender-specific "middleware" by hand - just wrap the handler function you want with something like this:
(fn my-wrapped-handler [data] (when (:?err data) (actual-handler data)))
Will check back tomorrow in case you need more details!
Thanks! I hadn't realised that.
I might also PR some Sentry-related improvements at some point.
Cheers - V
@vemv Great! Just ping if you'd like an actual working example 👍
@NoahTheDuke Thanks for your help on this, your advice re: (fn [data]) -> ?data
was fundamentally correct 👍
Hi @ptaoussanis ,
is it possible to skip a logging message for a specific appender, according to custom logic?
I'm not sure Timbre middleware can do that.
What I intend to accomplish is preventing the Sentry logger from logging messages that don't contain an exception, given that the Sentry logger will log everything past the
:min-level
.(It also seems feasible to just fork the Sentry logger. But this might be a nice use case for flexibility)
Thanks - V