5
votes

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?

3
Hibernate uses SFL4J for logging. What JARs do you have exactly on your classpath? What SFL4J binding? Do you only have log4j as logging backend?Pascal Thivent

3 Answers

2
votes

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.

0
votes

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.

0
votes

Can you try this syntax instead?

log4j.category.org.hibernate=ERROR