• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Setting up logging

 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, but how do I call the logging methods in my code?
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well for slf4j try here, log4j you can google a million examples
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

What does the contents of your log4j.properties look like?
 
Squanch that. And squanch this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!