aspose file tools*
The moose likes Other Open Source Projects and the fly likes Setting up logging 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 "Setting up logging" Watch "Setting up logging" New topic
Author

Setting up logging

Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Posts: 323
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?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

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.)
Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Posts: 323
Okay, but how do I call the logging methods in my code?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Well for slf4j try here, log4j you can google a million examples


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

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.
Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Posts: 323
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.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there,

What does the contents of your log4j.properties look like?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting up logging