无法禁用 Hibernate 日志消息
我正在将 Hibernate 用于个人项目。 在我的项目中,我有这些目录:
+ conf
log4j.properties
+ 垃圾箱
我的类
使用 Windows 控制台,我转到项目目录(bin 和 conf 的父目录)并开始使用如下命令的应用程序:
java -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
我的 log4j.properties 文件是这样的(取自一个休眠示例):
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
在应用程序启动时,这是输出:
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
Hibernate 日志行的颜色是红色,我的日志行是黑色。
为什么我仍然看到 Hibernate 的 INFO 输出?我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 log4j 配置和运行时发生的事件的一个好方法是添加
java 命令行的 -Dlog4j.debug 选项。在您的情况下,它将变成:
这将在控制台上抛出 log4j 配置加载顺序的信息。然后您可以确定 log4j.properties 是否正确加载。
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:
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.
您的 log4j 配置看起来不错,您的 log4j.properties 文件是否位于类路径和根包中?即它是否位于conf、lib1.jar、lib2.jar 或类路径中任何其他jar/目录的根目录中?
尝试此方法检查文件是否正确加载。
在此行上:
chage to
这将为根记录器设置日志级别,因此将所有记录器设置为错误,如果您仍然看到 INFO 日志条目,则您的 log4j.properties 文件一定无法正确加载,很可能是由于所述原因多于。
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:
chage to
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?