aspose file tools*
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
Author

Bugged with slf4j

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

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 log4j.properties 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
OR
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
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

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.

[Edit]
the jibx-tools.jar actually contains a log4j.properties file which was overriding my log4j.properties file...
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

the jibx-tools.jar actually contains a log4j.properties file which was overriding my log4j.properties 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: http://aspose.com/file-tools
 
subject: Bugged with slf4j