Java 无法禁用休眠日志消息
我正在使用Hibernate进行个人项目。 在我的项目中,我有以下目录: +confJava 无法禁用休眠日志消息,java,hibernate,logging,log4j,Java,Hibernate,Logging,Log4j,我正在使用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.l
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.patternalyout
log4j.appender.stdout.layout.ConversionPattern=%d-%m%n
log4j.rootLogger=info,标准输出
log4j.logger.org.hibernate=错误
log4j.logger.org.hibernate.tool.hbm2ddl=错误
log4j.logger.org.hibernate.hql.ast.QueryTranslatorImpl=错误
log4j.logger.org.hibernate.hql.ast.hqlslwalker=错误
log4j.logger.org.hibernate.hql.ast.SqlGenerator=错误
log4j.logger.org.hibernate.hql.ast.ast=错误
在应用程序启动时,这是输出:
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
2010-11-06 19:00:56376-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.driverManager连接提供程序-清理连接池:jdbc:mysql://localhost/mydb
Hibernate日志行的颜色是红色,我的日志行是黑色
为什么我仍然看到Hibernate的信息输出?我做错了什么?您的log4j配置看起来正常,您的log4j.properties文件是否在类路径和根包中?也就是说,它是否在conf、lib1.jar、lib2.jar的根目录中,或者在类路径中的任何其他jar/目录中 尝试此操作以检查文件是否正确加载 在这一行:
log4j.rootLogger=info, stdout
查格托
log4j.rootLogger=error, stdout
这会将根记录器的日志级别设置为错误,因此所有记录器都会设置为错误。如果您仍然看到INFO日志条目,则您的log4j.properties文件不能正确加载,很可能是由于上述原因。您可以改用此语法吗
log4j.category.org.hibernate=ERROR
检查log4j配置和运行时发生的事件的一个好方法是添加 -Dlog4j.debug选项添加到java命令行。在您的情况下,它将成为:
java -Dlog4j.debug -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
这将在控制台上抛出log4j配置加载顺序的信息。然后,您可以确定是否正确加载了log4j.properties。我的应用程序能够看到log4j.properties,因为rootLogger的错误级别使我无法看到我的Logger.getRootLogger().info(“hello”);-要加载conf文件,我使用PropertyConfigurator.configure(“conf/log4j.properties”);作为我申请的第一步。log4j.properties位于conf/log4j.properties中。我试着把它放在bin中(请参阅我文章中的dir层次结构),但没有任何改变hibernate使用SFL4J进行日志记录。你的类路径上到底有什么罐子?什么是SFL4J绑定?是否只有log4j作为日志后端?
java -Dlog4j.debug -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main