Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to disable Hibernate log messages

I'm using Hibernate for a personal project. In my project, I have these directory:

+ conf
log4j.properties
+ bin
my classes

Using Windows console, I go to project directory (the parent of bin and conf) and I start the application with a command like this:

java -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main

My log4j.properties file is this (taken from an hibernate example):

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 - %m%n

log4j.rootLogger=info, stdout

log4j.logger.org.hibernate=error
log4j.logger.org.hibernate.tool.hbm2ddl=error
log4j.logger.org.hibernate.hql.ast.QueryTranslatorImpl=error
log4j.logger.org.hibernate.hql.ast.HqlSqlWalker=error
log4j.logger.org.hibernate.hql.ast.SqlGenerator=error
log4j.logger.org.hibernate.hql.ast.AST=error

On application start, this is the output:

2010-11-06 19:00:56,376 - Logger.getRootLogger().info() statement
12 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.3-Final
13 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
16 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
20 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
108 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: com/moc/hibernate.cfg.xml
108 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: com/moc/hibernate.cfg.xml
124 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from file: conf\hiber\Customer.hbm.xml
.
.
.
and so on
.
.
.
795 [main] INFO org.hibernate.impl.SessionFactoryImpl - closing
795 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:mysql://localhost/mydb

The color of Hibernate log lines is red, my log lines are black.

Why I still see INFO output from Hibernate? What am I doing wrong?

like image 849
Antonio Avatar asked Nov 05 '22 06:11

Antonio


1 Answers

A good way of checking your log4j configuration and the events occuring at runtime is adding -Dlog4j.debug option to the java command line. In your case it will become:

java  -Dlog4j.debug -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main

This will throw information on console of the sequence of loading of log4j configuration. You can then determine if your log4j.properties is getting loaded correctly or not.

like image 90
harsh Avatar answered Nov 10 '22 04:11

harsh