Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up commons-logging to use logback?

We use slf4j + logback, and happened to have some third-party libraries which use commons-logging. How do I set it up to use logback?

like image 392
Artem Avatar asked Apr 12 '12 05:04

Artem


People also ask

Does Commons Logging use SLF4J?

This JAR, if included at runtime, should receive all logging calls from anything using Jakarta commons logging, and then re-route it to your SLF4J facade (from which you may log with any implementation you want).

Does Apache Commons Logging use log4j?

Apache Commons Logging is an abstraction for the concrete implementation. It uses log4j, if present and configured.

How do I set classpath for Apache Commons Logging?

Set CLASSPATH Variable Set the CLASSPATH environment variable to point to the Common Collections jar location. Assuming, you have stored commons-collections4-4.1-bin. zip in Apache folder on various Operating Systems as follows. export CLASSPATH=$CLASSPATH:$APACHE_HOME/commons-collections4-4.1-bin.


2 Answers

The answer is to not use commons-logging.jar, since SLF4J was designed to do what commons-logging does but better. As @MahdeTo refers to, you need to use jcl-over-slf4j.jar.

Check out the documentation from the slf4j website on migrating from commons-logging.

like image 71
Spencer Kormos Avatar answered Sep 23 '22 17:09

Spencer Kormos


I come across this question too, and found out jcl-over-slf4j.jar indeed can solve the problem, I couldn't understand that why commons-logging couldn't use logback automatically, since commons-logging is log interface and logback is implementation, they should integrate automatically, until I found this:

The Apache Commons Logging (JCL) provides a Log interface that is intended to be both light-weight and an independent abstraction of other logging toolkits. It provides the middleware/tooling developer with a simple logging abstraction, that allows the user (application developer) to plug in a specific logging implementation.

JCL provides thin-wrapper Log implementations for other logging tools, including Log4J, Avalon LogKit (the Avalon Framework's logging infrastructure), JDK 1.4, and an implementation of JDK 1.4 logging APIs (JSR-47) for pre-1.4 systems. The interface maps closely to Log4J and LogKit.

Obviously not all the log interface can integrate nicely with log implementation which mean, if you really want to use logback, jcl-over-slf4j.jar is your only solution now because JCL only support Log4J, Logkit, JDK 1.4.

like image 23
Sam YC Avatar answered Sep 21 '22 17:09

Sam YC