简体   繁体   English

如何配置Hibernate日志记录?

[英]How to configure Hibernate logging?

The sample application I am developing keeps writing all the Hibernate queries to Tomcat console. 我正在开发的示例应用程序继续将所有Hibernate查询写入Tomcat控制台。 I mean if you start Tomcat on Windows, you will have a small applet kind of window opened up. 我的意思是如果你在Windows上启动Tomcat,你将会打开一个小小的applet窗口。 Hibernate keeps writing all data access code like 'Hibernate: select table10_.col1 as COL10_, table10_.col2 as COL20_,..." I was wondering if there is any configuration I can set for Hibernate to write these queries to some kind of log file? Possibly to localhost-log under tomcat/logs? Hibernate不断编写所有数据访问代码,如'Hibernate:select table10_.col1 as COL10_,table10_.col2 as COL20 _,...“我想知道是否有任何配置我可以为Hibernate设置将这些查询写入某种日志文件?可能是tomcat / logs下的localhost-log?

That's not logging, it's Hibernate's "show_sql". 那不是日志,它是Hibernate的“show_sql”。 Look for a property named "hibernate.show_sql" being set to "true". 查找名为“hibernate.show_sql”的属性设置为“true”。 Change it to false or just remove it entirely to get rid of those. 将其更改为false或完全删除它以摆脱它们。 Then see the the Configuration chapter in the Hibernate ref for how to set up SQL logging in Hibernate. 然后参阅Hibernate参考资料中的Configuration章节 ,了解如何在Hibernate中设置SQL日志记录。

@Ryan-Stewart is right but it can be a Pass through Java JDBC driver that can log SQL and/or JDBC calls for other JDBC drivers. @ Ryan-Stewart是正确的,但它可以是一个Pass through Java JDBC驱动程序,可以记录SQL和/或JDBC calls其他JDBC驱动程序。

With hibernate's logging you have logging similar to : 使用hibernate的日志记录,您的日志记录类似于:

 select bs0_.A_REF as A2_7_0_ from B bs0_ where  bs0_.other = 0 and bs0_.A_REF=?  
 TRACE 2011-08-  03 00:30:45,317 binding '123' to parameter: 1

Note the '?' 注意'?' instead of the real parameter value. 而不是真实的参数值。

With Pass through JDBC driver you have logging similar to : 使用Pass through JDBC驱动程序,您的日志记录类似于:

select bs0_.A_REF as A2_7_0_ from B bs0_ where  bs0_.other = 0 and bs0_.A_REF=123  

All the bind parameter are resolved. 解析了所有绑定参数。

log4jdbc is one of those pass through JDBC driver. log4jdbc是其中一个通过JDBC驱动程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM