aspose file tools*
The moose likes Spring and the fly likes Getting Spring's FINE logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Getting Spring Watch "Getting Spring New topic
Author

Getting Spring's FINE logging

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
On Tomcat, I am trying to get the logging output from the Spring libraries that I am using on my project.

My problem is that I am not getting the FINE logging from Spring. However, for other libraries such as JSF, I do get the FINE logging. What am I doing wrong?

I have noticed that when I remove log4j.jar from the classpath, I do get logging from Spring. But when I add log4j.jar to the classpath, the logging from Spring is gone. Can you explain why?

BTW I do need log4j and commons-logging(JCL) in my classpath, since some of the other jars I am using, refer to log4j and JCL explicitly in their code.


Here are the settings I am using, in Tomcat's conf/logging.properties:



We must know, we will know. -- David Hilbert
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Yes, log4J needs to be in the classpath (usually WEN-INF/lib).

Do any changes in the properties file take effect?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
@Bear Bibeault: Why does log4j need to be in the classpath? AS far as I know, Spring uses Commons logging (JCL), so if there's no log4j on the classpath, it will use the JDK logging API (java.util.logging).

As I said, when I remove log4j from the classpath, the logging for some of the jars works (e.g. JSF jars), for others it doesn't (e.g. Spring jars). I wonder why. Any ideas?

Also, I am using log4j.xml to config log4j.

Changes to the conf/logging.properties do take effect. I am expecting to get the logging at the file ${catalina.home}/logs/catalina.log

Here is my conf/logging.properties:



My log4j.xml:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Because you said that one of your jars references log4j. If it's not on the classpath, you'll likely end up with a ClassNotFound exception.

BTW I do need log4j in my classpath, since one of the other jars I am using, refers to log4j explicitly in its code.


As to why Spring logging ceases to work with Log4J present, I can only assume that Spring uses Log4J if it is present, and reverts to Java logging otherwise (lots of stuff does this). And you likely have no Log4J config for Spring, so no logging.

But that's just a guess. Maybe you'd prefer this be moved to the Spring forum where the Spring-savvy hang out?
Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
@Bear Bibeault: I see, I thought you were trying to say that each time I need some jar to output its logging through Tomcat, I need log4j to be on the classpath.

I was actually wondering too which forum should be the best for posting this. So yes, if you think it has more to do with Spring, please move this thread to there. Thank you for this and for your answers!
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
This might help http://blog.springsource.org/2009/12/04/logging-dependencies-in-spring/
Manish Sridharan
Ranch Hand

Joined: Jul 19, 2005
Posts: 64
I too faced similar logging issues but able to resolve it by setting system parameter as -Dlog4j.configuration=log4j.properties and adding log4j.properties in the classpath.
Here is my log4j property file for reference.



Manish S.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Spring's FINE logging