Redirecting logback logs to log4j

Hi, I designed component, packaged in jars, using slf4j and logback, this library is then packaged with a third party application using log4j. I presumed that slf4j and logback could be used to change your log system depending on the loaded libraries of your classpath. Here my configuration: my_library.jar using only slf4j and at some point logback dependencies included with it: slf4j-to-log4j.jar slf4j.jar log4j.jar --> already present in the war. logback-*.jar All these libraries are installed into a third part webapp application (client_app.war), directly under the WEB-INF/lib directory of this application. This application has a log4j.properties, in the classes directory, changes are made to create a log4j logger. At my understanding, my library's log events should be redirecting from slf4j/logback to log4j, using the log4j.properties, and so be written in the "client_app..log" configured? Am I wrong? Do I still need a logback.xml to be located under the classes of this webapps as well? Regards, Johan Bos

Hello Johan, Could you please read the slf4j manual [1] and the page on Bridging legacy APIs [2]. Those pages contain the explanation you are seeking. However, if you are still confused about how to proceed, please contact this list once again. [1] http://www.slf4j.org/manual.html [2] http://www.slf4j.org/legacy.html Johan Bos wrote:
Hi,
I designed component, packaged in jars, using slf4j and logback, this library is then packaged with a third party application using log4j.
I presumed that slf4j and logback could be used to change your log system depending on the loaded libraries of your classpath.
Here my configuration:
my_library.jar using only slf4j and at some point logback dependencies
included with it:
slf4j-to-log4j.jar slf4j.jar log4j.jar à already present in the war. logback-*.jar
All these libraries are installed into a third part webapp application (client_app.war), directly under the WEB-INF/lib directory of this application.
This application has a log4j.properties, in the classes directory, changes are made to create a log4j logger.
At my understanding, my library’s log events should be redirecting from slf4j/logback to log4j, using the log4j.properties, and so be written in the “client_app..log” configured?
Am I wrong?
Do I still need a logback.xml to be located under the classes of this webapps as well?
Regards,
Johan Bos**
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

I already read the documentation, I only omitted that logback was also considered as one binder as well So I can't have both slf4j-to-log4j and logback, this point is clear now At first what I wanted was to redirect all logs from log4j to slf4j and us logback as implementation, but it seems that the client-app.war use some log4j non-overload classes, not included into the bridge lib: log4j-to-slf4j.jar That s why I decided to go with the log4j implementation, but I forgot that even if logback support natively slf4, that still makes it one of the implementation, so it can't be both in use. My bad, I will test it, as I don't have direct dependency over logback with this library. I should work Thanks -----Message d'origine----- De : logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] De la part de Ceki Gulcu Envoyé : mercredi 19 août 2009 10:52 À : logback users list Objet : Re: [logback-user] Redirecting logback logs to log4j Hello Johan, Could you please read the slf4j manual [1] and the page on Bridging legacy APIs [2]. Those pages contain the explanation you are seeking. However, if you are still confused about how to proceed, please contact this list once again. [1] http://www.slf4j.org/manual.html [2] http://www.slf4j.org/legacy.html Johan Bos wrote:
Hi,
I designed component, packaged in jars, using slf4j and logback, this library is then packaged with a third party application using log4j.
I presumed that slf4j and logback could be used to change your log system depending on the loaded libraries of your classpath.
Here my configuration:
my_library.jar using only slf4j and at some point logback dependencies
included with it:
slf4j-to-log4j.jar slf4j.jar log4j.jar à already present in the war. logback-*.jar
All these libraries are installed into a third part webapp application (client_app.war), directly under the WEB-INF/lib directory of this application.
This application has a log4j.properties, in the classes directory, changes are made to create a log4j logger.
At my understanding, my librarys log events should be redirecting from slf4j/logback to log4j, using the log4j.properties, and so be written in the client_app..log configured?
Am I wrong?
Do I still need a logback.xml to be located under the classes of this webapps as well?
Regards,
Johan Bos**
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Johan Bos wrote:
I already read the documentation,
I only omitted that logback was also considered as one binder as well
Yes, logback-classic is an slf4j binding.
So I can't have both slf4j-to-log4j and logback, this point is clear now
At first what I wanted was to redirect all logs from log4j to slf4j and us logback as implementation, but it seems that the client-app.war use some log4j non-overload classes, not included into the bridge lib: log4j-to-slf4j.jar
That s why I decided to go with the log4j implementation, but I forgot that even if logback support natively slf4, that still makes it one of the implementation, so it can't be both in use.
My bad, I will test it, as I don't have direct dependency over logback with this library.
Note that you still need an slf4j binding which needs to be slf4j-log4j12 in your case. Quoting the manual: log4j-over-slf4j.jar and slf4j-logj12.jar cannot be present simultaneously The presence of slf4j-logj12.jar, that is the log4j binding for SLF4J, will force all SLF4J calls to be delegated to log4j. The presence of log4j-over-slf4j.jar will in turn delegate all log4j API calls to their SLF4J equivalents. If both are present simultaneously, slf4j calls will be delegated to log4j, and log4j calls redirected to SLF4j, resulting in an endless recursion. Since log4j-to-slf4j.jar and slf4j-log4j12.jar cannot co-exist, you need to remove log4j-to-slf4j.jar from your class path, which should then consist of slf4j-api-1.5.8.jar slf4j-log4j12-1.5.8.jar log4j.jar (1.5.8 is the latest SLF4J release) HTH, -- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch
participants (2)
-
Ceki Gulcu
-
Johan Bos