Turning off hibernate logging console output
I'm using hibernate 3 and want to stop it from dumping all the startup messages to the console. I tried commenting out the stdout lines in log4j.properties but no luck. I've pasted my log file below. Also I'm using eclipse with the standard project structure and have a copy of log4j.properties in both the root of the project folder and the bin folder.
### direct log messages to stdout ### #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 ### direct messages to file hibernate.log ### log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=hibernate.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### log4j.rootLogger=warn, stdout #log4j.logger.org.hibernate=info log4j.logger.org.hibernate=debug ### log HQL query parser activity #log4j.logger.org.hibernate.hql.ast.AST=debug ### log just the SQL #log4j.logger.org.hibernate.SQL=debug ### log JDBC bind parameters ### log4j.logger.org.hibernate.type=info #log4j.logger.org.hibernate.type=debug ### log schema export/update ### log4j.logger.org.hibernate.tool.hbm2ddl=debug ### log HQL parse trees #log4j.logger.org.hibernate.hql=debug ### log cache activity ### #log4j.logger.org.hibernate.cache=debug ### log transaction activity #log4j.logger.org.hibernate.transaction=debug ### log JDBC resource acquisition #log4j.logger.org.hibernate.jdbc=debug ### enable the following line if you want to track down connection ### ### leakages when using DriverManagerConnectionProvider ### #log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trac5
Important notice: the property (part of hibernate configuration, NOT part of logging framework config!)
hibernate.show_sql
controls the logging directly to STDOUT bypassing any logging framework (which you can recognize by the missing output formatting of the messages). If you use a logging framework like log4j, you should always set that property to false because it gives you no benefit at all.
That circumstance irritated me quite a long time because I never really cared about it until I tried to write some benchmark regarding Hibernate.
Try to set more reasonable logging level. Setting logging level to info
means that only log event at info
or higher level (warn
, error
and fatal
) are logged, that is debug
logging events are ignored.
log4j.logger.org.hibernate=info
or in XML version of log4j config file:
<logger name="org.hibernate">
<level value="info"/>
</logger>
See also log4j manual.
Executing:
java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.OFF);
before hibernate's initialization worked for me.
Note: the line above will turn every logging off (Level.OFF
). If you want to be less strict, you can use
java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.SEVERE);
that is silent enough. (Or check the java.util.logging.Level
class for more levels).