Skip to content

palletops/log-config

Repository files navigation

log-config

A Clojure library designed to help configure your timbre logging.

The com.palletops.log-config.timbre namespace provides timbre middleware and formatters.

Add [com.palletops/log-config "0.1.4"] to your dependencies.

Filtering Levels by Namespace

The min-level function provides a timbre middleware to filter log messages for a single namespace to those at or above a threshold level.

The min-levels function provides a timbre middleware to filter log messages based on a map from namespace to a threshold level.

The min-level-appender function provides an appender adaptor to filter log messages based on a map from namespace to a threshold level provided in the :min-levels timbre configuration key.

Domain Based Logging

For logs at the domain level, the namespace is often irrelevant. The with-domain macro allows specifying a domain keyword for a dynamic clojure scope. The domain-msg timbre middleware adds this domain keyword to log messages on the :domain key. The format-with-domain timbre formatter will show the domain in preference to the namespace if the :domain key is set.

Logging Contexts

Often, the same code is called in multiple contexts, and the log message would be improved by adding some of that contextual information. The with-context macro allows specifying a data map for a dynamic clojure scope. The context-msg timbre middleware adds this context map to log messages on the :context key. The format-with-context timbre formatter will show the context keys and value in the log message.

There is also a format-with-domain-context that shows both domain and context values.

Tags for Filtering Log Messages

To allow domain level filtering of log messages, use the with-tags macro, specifying a set of keywords. The tags-msg timbre middleware adds this tag set on the :tags key.

Add Log Message Key based on a Var

The add-var function returns a timbre middleware to set a log message key based on the value of the specified var.

Timbre and Java Logging

There are a number of logging choices on the JVM. Different libraries you use may depend on different logging libraries. If you're writing a library, you may wish to allow for logging via Java Logging, while still using timbre.

Logging From Timbre to Java Logging

The com.palletops.log-config.timbre.tools-logging namespace provides the make-tools-logging-appender function, that returns a timbre appender that outputs to tools.logging.

To use it, add an entry in your timbre configuration :appenders:

:appenders {:jl (make-tools-logging-appender {})

Logging java logging to timbre

See taoensso.timbre.tools.logging.

Logging in Tests

Sometimes it is useful to be able to modify log levels in tests. We provide the logging-threshold-fixture function for use as a clojure.test fixture, and suppress-logging which provides a scope where all configured appenders are disabled.

License

Copyright © 2014 Hugo Duncan

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Logging configuration with timbre

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •