File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Bugged with slf4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Bugged with slf4j" Watch "Bugged with slf4j" New topic

Bugged with slf4j

Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

I'm working on a desktop application which uses Hibernate. So the logging is done through slf4j. I later added JasperReports to the project (which uses commons logging) and after that logging stopped working. I read these two articles - this and this and it made me even more confused. What I learned was that to work with slf4j, I need slf4j api jar, slf4j adapter jar and any bridge jars as required. Basically what I want is my application has a log4j property configuration file and I want to do logging through log4j. My file (which is at the root of the classpath) looks like this
Here jewelapp is the package name in which there are other packages which contain my classes. This is how I'm trying to log messages
Currently I have these jar files in the app for logging

slf4j-api-1.5.11.jar             <--base library
slf4j-log4j12-1.5.11.jar      <--log4j adapter
log4j-over-slf4j-1.5.11.jar  <--log4j bridge
jcl-over-slf4j-1.5.11.jar       <--commons logging bridge

I've tried with adding log4j.jar to classpath and without it but it doesn't work in both cases (one of the articles that I linked says I need to put it in classpath, the other says not to put it there). I've wasted over 4 hours on this and I'm still not sure what I'm doing wrong. Any help would be appreciated...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

Ohh man, I found the problem. I was using JiBX in the project and I put jibx-tools.jar on the classpath. Somewhere it must have been initializing log4j to BasicConfiguration that's why logging messages were going on the console. I removed it from classpath and it started working. Also log4j-over-slf4j-1.5.11.jar was not required in the classpath and log4j.jar was required in the classpath. I can't believe how much time I spent playing with log4j configurations and the problem was a library in the classpath.

the jibx-tools.jar actually contains a file which was overriding my file...
Peter Johnson

Joined: May 14, 2008
Posts: 5852

the jibx-tools.jar actually contains a file which was overriding my file...

I have run into similar situations and it always makes me wonder what goes on in the mind of a developer who packages a logging properties file into a library JAR file. Though I guess in this case they did not think that someone would use a "tools" JAR as a library.

JBoss In Action
I agree. Here's the link:
subject: Bugged with slf4j
It's not a secret anymore!