I'm not really sure where this goes since it involves a couple different things, of which I'm not sure what all is relevant.
I'm creating a web service using Axis2. It's hosted on Tomcat, and uses Hibernate as the back end.
Right now I'm using simple println's to the console for my logging/tracing. I want to take advantage of the java logging, but I'm not exactly sure where to start. From what I understand, Hibernate uses slf4j to do it's logging, which sits on log4j.
How do I go about setting up my application to take advantage of all of the slf4j stuff that's already set up for Hibernate?
You choose your preferred method of logging. It could be log4j but it doesn't have to be, SLF will work with a lot of logging frameworks.
But let's suppose you choose log4j. Then you put a log4j configuration file (log4j.properties if you like, but there's an XML format too) in your application's classpath. Put the log4j.jar into your application's WEB-INF/lib directory, and also the SLF jar file which works with log4j. Its name is something like slf4j-log4jxx-xxx.jar, get the current version from the SLF download site. You'll also need the base SLF jar file there, its name is like slf4j-api-xxx.jar.
That's all you need to do. At least that's all I did, and both my web application and Hibernate are happily logging to the places my log4j configuration says to log to.
(And don't be like me: googling for "SFL" doesn't find you anything useful. It's "SLF" you have to google for. I've just been through my post correcting "SFL" to "SLF" throughout. Don't know why I do that.)
posted 10 years ago
Okay, but how do I call the logging methods in my code?
Just because Hibernate uses slf4j, that doesn't mean you have to. What I have done in my project is to drop in the SLF jar files which cause Hibernate's logging to be handled by log4j. In my code I just log directly to log4j. Same log4j.properties file. Works fine.
posted 10 years ago
Okay, I followed the instructions at the SLF page, but my logging isn't showing up. I'm getting all of the Hibernate, Axis2, and Tomcat logging, though.
I have a log4j.properties file in WEB-INF/classes. When I set it to WARNING instead of INFO, I got a lot of DEBUG statements from Axis2, which I thought was weird.