Skip to content
Dennis Schridde edited this page Jan 10, 2025 · 5 revisions

tools.logging

tools.logging can use Timbre as its logging implementation (backend). This'll let tools.logging calls trigger Timbre logging calls.

To do this:

  1. Ensure that you have the tools.logging dependency, and
  2. Require the taoensso.timbre.tools.logging namespace
  3. Call taoensso.timbre.tools.logging/use-timbre

Java logging

SLF4Jv2 can use Timbre as its logging backend. This'll let SLF4J logging calls trigger Timbre logging calls.

To do this:

  1. Ensure that you have the SLF4J dependency ( v2+ only), and
  2. Ensure that you have the Timbre SLF4J backend dependency

When com.taoensso/timbre-slf4j (2) is on your classpath AND no other SLF4J backends are, SLF4J will automatically direct all its logging calls to Timbre.

If you want to have more control, you can set the slf4j.provider Java system property to the Timbre SLF4J service provider: -Dslf4j.provider=com.taoensso.timbre.slf4j.TimbreServiceProvider

If you want to debug which provider is being used, you can enable SLF4J internal debug messages via the slf4j.internal.verbosity Java system property: -Dslf4j.internal.verbosity=DEBUG

If you do not see log messages from code that should use SLF4J (e.g. the OpenTelemetry Java agent configured with the otel.javaagent.logging Java system property), or the log messages are not processed by Timbre (e.g. the output format differs), then you might need to call (org.slf4j.LoggerFactory/getLogger (str *ns*)) right after application start (i.e. at the beginning of your -main Clojure function) to initialize SLF4J.

Timbre needs SLF4J API version 2 or newer. If you're seeing Failed to load class "org.slf4j.impl.StaticLoggerBinder" it could be that your project is importing the older v1 API, check with lein deps :tree or equivalent.

For other (non-SLF4J) logging like Log4j, java.util.logging (JUL), and Apache Commons Logging (JCL), use an appropriate SLF4J bridge and the normal SLF4J config as above.

In this case logging will be forwarded:

  1. From Log4j/JUL/JCL/etc. to SLF4J, and
  2. From SLF4J to Timbre
Clone this wiki locally