Caffeine: Start using slf4j for logging instead of java.util.logging

Created on 17 Sep 2020  ·  2Comments  ·  Source: ben-manes/caffeine

It's easy to use slf4j as abstraction over concrete logging framework: logback, log4j, java.util.logging. All we need is to add jar on classpath: http://slf4j.org/manual.html

Motivation:

We want to use caffeine in library code, but it is currently not possible to disable logging for caffeine in library layer.
Application not using java.util.logging should to do something [that] (https://stackoverflow.com/questions/6020545/send-redirect-route-java-util-logging-logger-jul-to-logback-using -slf4j) just to disable caffeine logs.

I think it would be simpler with slf4j as logging facade. WDYT ?

Most helpful comment

We log minimally, ideally not at all, and primarily only warnings that do not affect the cache's correctness. The primary time you might observe logging is due to a convenience warning when an AsyncCache future is removed due to an error. An unfortunately common mistake is to forget to include an error handler on a CompleteableFuture and then wonder why the cache entry disappeared.

Currently Caffeine mirror's Google Guava which uses JUL. It's generally good practice to install the adapters from other loggers to slf4j as a fallback. For example I use logback at work but have log4j, jul, and system out/err redirect to slf4j.

The next major version will use JEP-264: Platform Logging API, which avoids the dependency, is backwards compatible by defaulting to JUL, and has a cleaner mechanism for redirecting to slf4j. However that requires Java 9.

All 2 comments

We log minimally, ideally not at all, and primarily only warnings that do not affect the cache's correctness. The primary time you might observe logging is due to a convenience warning when an AsyncCache future is removed due to an error. An unfortunately common mistake is to forget to include an error handler on a CompleteableFuture and then wonder why the cache entry disappeared.

Currently Caffeine mirror's Google Guava which uses JUL. It's generally good practice to install the adapters from other loggers to slf4j as a fallback. For example I use logback at work but have log4j, jul, and system out/err redirect to slf4j.

The next major version will use JEP-264: Platform Logging API, which avoids the dependency, is backwards compatible by defaulting to JUL, and has a cleaner mechanism for redirecting to slf4j. However that requires Java 9.

Released in 3.0

Was this page helpful?
0 / 5 - 0 ratings