views:

31

answers:

2

I am using JSF 2.0, Spring, Hibernate and I need to implement Log4J for centralized error catching. Can anybody help?

A: 

log4j has absolutely nothing to do with spring, jsf or hibernate.

  • place log4j.jar in WEB-INF/lib
  • get a sampel log4j.properties and place in on the root of your classpath
  • use private static final Logger log = Logger.getLogger(CurrentClass.class);
Bozho
A: 

If you want centralized logging and since you are using Spring and Hibernate, things are a bit more complicated than just providing a log4j.properties because Hibernate uses SLF4J as logging facade while Spring uses Jakarta Commons Logging (JCL) as logging facade and they seem to conflict.

My recommendation would be to use SLF4J and for that, you'll need to:

  • provide slf4j-api.jar (you should actually get this one with Hibernate)
  • remove commons-logging.jar that comes from Spring
  • provide jcl-over-slf4j.jar to bridge JCL calls to SLF4J
  • provide the SLF4J binding for Log4J (slf4j-log4j12.jar) to bridge SLF4J calls to Log4J
  • provide log4j.jar

See also

Pascal Thivent