Hibernate 4 uses JBoss logging rather than slf4j used in earlier versions. For log4j configuration, we need to follow below steps.
* Add log4j dependencies for maven project, if not maven then add corresponding jar files.
* Create log4j.xml configuration file or log4j.properties file and keep it in the classpath. You can keep file name whatever you want because we will load it in next step.
* For standalone projects, use static block to configure log4j using DOMConfigurator
or PropertyConfigurator
. For web applications, you can use ServletContextListener
to configure it.
* That’s it, our setup is ready. Create org.apache.log4j.Logger
instance in the java classes and start logging.