Thursday, March 31, 2011

Setting up logging for Hibernate

In fact it took me a while to find out that I am actually missing a jar in the classpath while doing the same. Had the below jars in the application classpath,

slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
log4j-1.2.16.jar and had log4j.properties in the classpath. Make sure you have your log4j.properties preceeding over other files (if at all others exist).

My log4j.properties are copied from hibernate's example properties
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

log4j.rootLogger=info,stdout,R

log4j.logger.org.hibernate=debug
log4j.logger.org.hibernate.test=info
log4j.logger.org.hibernate.tool.hbm2ddl=debug
log4j.logger.org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator=warn

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=hibernate.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

No comments:

Post a Comment