How to configure logging in Hibernate – Logback

In this tutorial, we show how to integrate Logback logging framework with Hibernate.

Tools and Technologies used in this tutorial :

  1. Hibernate 3.6.3.Final
  2. slf4j-api-1.6.1
  3. logback-core-0.9.28
  4. logback-classic-0.9.28
  5. Eclipse 3.6
  6. Maven 3.0.3

1. Get SLF4j + Logback

To use logback in Hibernate web application, you need 3 libraries :

  1. slf4j-api.jar
  2. logback-core
  3. logback-classic

File : pom.xml

<project ...>
			<id>JBoss repository</id>



		<!-- logback -->


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. logback.xml

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

logback hibernate

A classic “logback.xml” example.

<?xml version="1.0" encoding="UTF-8"?>

 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
	<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
		<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} %-5level %logger{36} - %msg%n

 <appender name="FILE"
	<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
	   <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n

	<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">



  <logger name="org.hibernate.type" level="ALL" />
  <logger name="org.hibernate" level="DEBUG" />

  <root level="INFO">
	<appender-ref ref="FILE" />
	<appender-ref ref="STDOUT" />


With this logback.xml configuration, it means, redirect all your web application logging outputs to console and also a file at “c:/mkyongapp.log“.

3. Output

See logback logging output at “C:\\mkyongapp.log” below :

2011-04-23_14:34:08.055 [main] DEBUG o.h.transaction.JDBCTransaction - commit
2011-04-23_14:34:08.056 [main] DEBUG o.h.e.d.AbstractFlushingEventListener - processing flush-time cascades
2011-04-23_14:34:08.056 [main] DEBUG o.h.e.d.AbstractFlushingEventListener - dirty checking collections
2011-04-23_14:34:08.058 [main] DEBUG o.h.e.d.AbstractFlushingEventListener - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2011-04-23_14:34:08.058 [main] DEBUG o.h.e.d.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2011-04-23_14:34:08.059 [main] DEBUG org.hibernate.pretty.Printer - listing entities:
2011-04-23_14:34:08.060 [main] DEBUG org.hibernate.pretty.Printer - com.mkyong.user.DBUser{username=Hibernate101, createdBy=system, userId=100, createdDate=Sat Apr 23 14:34:08 SGT 2011}
2011-04-23_14:34:08.064 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2011-04-23_14:34:08.066 [main] DEBUG org.hibernate.SQL - insert into MKYONG.DBUSER (CREATED_BY, CREATED_DATE, USERNAME, USER_ID) values (?, ?, ?, ?)
2011-04-23_14:34:08.150 [main] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - system
2011-04-23_14:34:08.152 [main] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [DATE] - Sat Apr 23 14:34:08 SGT 2011
2011-04-23_14:34:08.153 [main] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - Hibernate101
2011-04-23_14:34:08.153 [main] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [4] as [INTEGER] - 100
Download it – (8KB)


  1. Simple Logging Facade for Java (SLF4J)
  2. Logback logging framework

About the Author

author image
Founder of, 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.


Leave a Reply

newest oldest most voted

for web application, this don’t works.

Camilo Lopes
Camilo Lopes

how can i do it works on jee project? I have tried, but the file is not created. Where should i put logback.xml file?
thanks. good post.


Hi I am not able to generate the log files….though I am able to print the output in the console, could you please explain me that


Hi Mkyong, another good tutorials :)

But in this current time, Hibernate 4 using jboss.logging for their logging system.

In my project, i use pure Hibernate 4 and Logback only, and it seems not produce any hibernate log.

So what is the solution?
Adding logging facade using SLF4j?

Thankyou :)


Is it possible to amend to files path of the log so that you create your log in src/main/resources??? I have n app that will create some logs and then interogate them. so I would like to keep my logs on the classpath

Daniel Serodio
Daniel Serodio

That doesn’t make sense. “src/main/resources/” is on the “build path”, not the classpath. “target/classes/” (where Maven-compiled classes and other resources are copied to) is on the classpath.

How to configure logging in Hibernate – SLF4j + Log4j

[…] refer to this – How to configure logging in Hibernate – Logback Hibernate uses Simple Logging Facade for Java (SLF4J) to redirect the logging output to your […]