无法禁用Hibernate日志消息 [英] Unable to disable Hibernate log messages

查看:197
本文介绍了无法禁用Hibernate日志消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Hibernate作为个人项目。
在我的项目中,我有这些目录:



+ conf <
log4j.properties

+ bin

我的课程



使用Windows控制台,我转到项目目录(bin和conf的父目录),然后使用如下命令启动应用程序:

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



我的log4j.properties文件是这样的(取自一个hibernate示例):

 
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 =错误
log4j.logger.org .hibernate.tool.hbm2ddl =错误
log4j.logger.org.hibernate.hql.ast.QueryTranslatorImpl =错误
log4j.logger.org.hibernate.hql.ast.HqlSqlWalker =错误
log4j.logger.org.hibernate.hql.ast.SqlGenerator =错误
log4j.logger.org.hibernate .hql.ast.AST =错误

在应用程序启动时,这是输出:

 
2010-11-06 19:00:56,376 - Logger.getRootLogger().info()语句
12 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.3-Final
13 [main] INFO org.hibernate.cfg.Environment - 找不到hibernate.properties
16 [main] INFO org.hibernate.cfg.Environment - 字节码提供程序名称:javassist
20 [main] INFO org.hibernate.cfg.Environment - 使用JDK 1.4 java.sql.Timestamp处理
108 [main] INFO org.hibernate.cfg.Configuration - 从资源配置:com / moc / hibernate.cfg.xml
108 [main] INFO org.hibernate.cfg.Configuration - 配置资源:com / moc / hibernate.cfg.xml
124 [main] INFO org.hibernate.cfg.Configuration - 从文件读取映射:conf \hiber\Customer。 hbm.xml



等等



795 [main] INFO org.hibernate.impl.SessionFactoryImpl - 关闭
795 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - 清理连接池:jdbc:mysql:// localhost / mydb

Hibernate日志行的颜色是红色的,我的日志行是黑色的。

为什么我仍然看到Hibernate的INFO输出?我在做什么错了?

解决方案

检查log4j配置和运行时发生的事件的好方法是添加
-Dlog4j.debug 选项添加到java命令行中。在你的情况下,它将变成:

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

这会在控制台的信息的log4j配置。然后,您可以确定您的log4j.properties是否正确加载。


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?

解决方案

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.

这篇关于无法禁用Hibernate日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆