taoensso / timbre

Pure Clojure/Script logging library
https://www.taoensso.com/timbre
Eclipse Public License 1.0
1.44k stars 171 forks source link

Filter by context #347

Closed awb99 closed 2 years ago

awb99 commented 2 years ago

Is it possible to filter in an appender by context?

ptaoussanis commented 2 years ago

@awb99 Sure. This can be done in the appender itself, or in middleware (if the same behaviour can/should apply to all appenders). Context is available to appenders along with other appender data.

If you want this behaviour for your own appender (fn) implementation, it's as simple as checking the value of :context sent to the appender in the appender fn body.

If you want this behaviour for an appender (fn) that someone else implemented (e.g. one of the built-in appenders), the easiest way would probably be to just write a little appender wrapper that checks the value of :context then either noops or calls the underlying appender.

Timbre appenders are just functions of appender data to side effects. So they can be written, composed, wrapped, etc. the same as any other Clojure functions.

Hope that helps!