Try logback
Try logback logging framework, read this article for the “reasons to prefer logback over log4j. To integrate logback with Hibernate, refer this – How to configure logging in Hibernate – Logback

Hibernate uses Simple Logging Facade for Java (SLF4J) to redirect the logging output to your perfer logging frameworkis (log4j, JCL, JDK logging, lofback…). In this tutorial, we show you how to do logging in Hibernate with SLF4j + Log4j logging framework.

Technologies used in this article :

  1. Hibernate 3.6.3.Final
  2. slf4j-api-1.6.1
  3. slf4j-log4j12-1.6.1
  4. Eclipse 3.6
  5. Maven 3.0.3

1. Get SLF4j + Log4j

To do logging in Hibernate, you need “slf4j-api.jar” and your preferred binding, like log4j “slf4j-log4j12.jar“. Just declares the dependency in your pom.xml.

File : pom.xml

<project ...>
			<id>JBoss repository</id>
		<!-- slf4j-log4j -->
Where is slf4j-api.jar?
The slf4j-api.jar is defined as the dependency of “hibernate-core“, so , you do not need to declare it again.

2. Log4j properties file

Create a “” file and put it into your project’s classpath, see figure below :

configure log4j in hibernate

File :

# Direct log messages to a log file
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Log everything. Good for troubleshooting
# Log all JDBC parameters

With this log4j configuration, it will redirect all the logging output to console and also a file at “C:\\mkyongapp.log“.

Hibernate provides many settings to let developer to decide what to log. Always refer to this Hibernate Log Categories, choose some and implement it in your log file.

3. Output

Try run your Hibernate web application, all logging output will be logged in “C:\\mkyongapp.log” file. See figure below :

log4j output
Download it – (7KB)


  1. Simple Logging Facade for Java (SLF4J)
Tags :
Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Related Posts

Popular Posts