开发者

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 IN开发者_开发百科FO output from Hibernate? What am I doing wrong?


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.


Your log4j configuration looks ok, is your log4j.properties file on the classpath and in the root package? I.e. is it in the root of conf, lib1.jar, lib2.jar pr any other jar/directory in your classpath?

Try this to check if the file is being loaded correctly.

On this line:

log4j.rootLogger=info, stdout

chage to

log4j.rootLogger=error, stdout

This will set the log level for the root logger and hence all loggers to ERROR, if you are still seeing the INFO log entries then your log4j.properties file must not be loading correctly, most likely for the reasons stated above.


Can you try this syntax instead?

log4j.category.org.hibernate=ERROR
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜