如何为 Hibernate 的 JUnit 测试配置公共日志记录

发布于 2024-10-28 02:05:46 字数 1321 浏览 0 评论 0原文

我正在尝试使用 junit 测试和公共日志记录来调试 Spring 应用程序中的一些休眠功能,但除了默认的 INFO 消息之外,我似乎无法看到任何其他内容。我还从 Eclipse 运行这些 junit 测试。

我在春季论坛上也没有运气。

我对 Hibernate 的调试日志输出特别感兴趣(尝试找出为什么运行此测试需要 23 秒)。

当前输出显示 INFO 的默认设置:

Mar 29, 2011 4:44:35 PM org.springframework.test.AbstractTransactionalSpringContextTests onSetUp
INFO: Began transaction: transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@5f873eb2]; defaultRollback true
testGetSubjectsForSite time: [00:00:00:068]
Mar 29, 2011 4:44:58 PM org.springframework.test.AbstractTransactionalSpringContextTests endTransaction
INFO: Rolled back transaction after test execution

我尝试将 commons-logging.properties 文件添加到类路径(与 hibernate.properties 和 test-components.xml 相同的位置),但仍然只显示默认的 INFO 消息。

这是 commons-logging.properties 文件:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger

# handlers
handlers=java.util.logging.ConsoleHandler

# default log level
.level=FINE
org.springframework.level=FINE
org.hibernate.level=FINE

# level for the console logger
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

有谁能够解释为什么我无法打印调试消息吗?我是否缺少日志记录设置?

编辑:我尝试过 FINEST 和 DEBUG 但无济于事。

I'm trying to debug some hibernate functionality in a spring app with a junit test and commons logging, but I can't seem to get anything other than the default INFO messages to appear. I'm also running these junit tests from Eclipse.

I've had no luck from the spring forums either.

I'm particularly interested in the debug logging output by Hibernate (to try and figure out why it takes 23 seconds to run this test).

Current output shows the default setting of INFO:

Mar 29, 2011 4:44:35 PM org.springframework.test.AbstractTransactionalSpringContextTests onSetUp
INFO: Began transaction: transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@5f873eb2]; defaultRollback true
testGetSubjectsForSite time: [00:00:00:068]
Mar 29, 2011 4:44:58 PM org.springframework.test.AbstractTransactionalSpringContextTests endTransaction
INFO: Rolled back transaction after test execution

I've tried to add a commons-logging.properties file to the classpath (the same location as the hibernate.properties and test-components.xml) but still only the default INFO messages appear.

Here's the commons-logging.properties file:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger

# handlers
handlers=java.util.logging.ConsoleHandler

# default log level
.level=FINE
org.springframework.level=FINE
org.hibernate.level=FINE

# level for the console logger
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

Is anyone able to shed any light on why I can't get the DEBUG messages to print out? Is there a logging setting I'm missing?

Edit: I've tried FINEST and DEBUG to no avail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烈酒灼喉 2024-11-04 02:05:47

您的默认和休眠日志记录处于“FINE”级别,这在 log4j 术语中更像是“INFO”。

您需要为 org.hibernate 设置 DEBUG 级别,该级别在 JDK 日志记录中等于“FINEST”


org.hibernate.level=FINEST(在上面的日志中应该启用调试日志)

Your default and hibernate logging is at Level "FINE" which is more of a "INFO" in log4j terms.

You need set DEBUG level for org.hibernate which in JDK logging is equal to 'FINEST'

Set
org.hibernate.level=FINEST (in the above log which should enable debug logs)

纸伞微斜 2024-11-04 02:05:46

不幸的是,Jdk14Logger 使用的日志配置文件似乎应该在运行时指定。
请参阅 JDK 目录中的以下文件:JDK_HOME/jre/lib/logging.properties(如果未找到配置文件,则使用默认文件)
此外,文件路径应该是绝对路径,否则它是相对于执行 JRE 的文件夹 - 请参阅 java.util.logging.LogManager.readConfiguration() 的代码

另请参阅:
http://www.javapractices.com/topic/TopicAction.do?Id=143
http://cyntech.wordpress.com/2009/01/09/how-to-use-commons-logging/

Unfortunately, it seems the logging configuration file used by Jdk14Logger should be specified at runtime.
See the following file in your JDK directory: JDK_HOME/jre/lib/logging.properties (it's the default one used if no config file is found)
Moreover, the file path should be absolute, otherwise it's relative to the folder where the JRE is executed - see the code of java.util.logging.LogManager.readConfiguration()

Also see:
http://www.javapractices.com/topic/TopicAction.do?Id=143
http://cyntech.wordpress.com/2009/01/09/how-to-use-commons-logging/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文