关闭控制台的休眠日志记录
运行 Spring/Hibernate 应用程序时,我在控制台上看到以下不需要的输出:
Hibernate: select securityus0_.ID ....
Hibernate: select securityus0_.ID ....
Hibernate: select securityus0_.ID ....
Hibernate: select securityus0_.ID ....
我已像这样配置了 Log4j 记录器:
<logger name="org.hibernate">
<level value="FATAL"/>
</logger>
<category name="STDOUT">
<priority value="WARN"/>
</category>
<category name="STDERR">
<priority value="WARN"/>
</category>
<!-- for all other loggers log only info and above log messages -->
<root>
<priority value="WARN"/>
<appender-ref ref="STDOUT" />
</root>
如何使这些消息静音?
When running my Spring/Hibernate application I see the following unwanted output on the console:
Hibernate: select securityus0_.ID ....
Hibernate: select securityus0_.ID ....
Hibernate: select securityus0_.ID ....
Hibernate: select securityus0_.ID ....
I have configured my Log4j logger like so:
<logger name="org.hibernate">
<level value="FATAL"/>
</logger>
<category name="STDOUT">
<priority value="WARN"/>
</category>
<category name="STDERR">
<priority value="WARN"/>
</category>
<!-- for all other loggers log only info and above log messages -->
<root>
<priority value="WARN"/>
<appender-ref ref="STDOUT" />
</root>
How do I silence these messages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我相当确定您看到了这些 SQL 语句,因为在您的 Hibernate 配置中的某个位置,属性“hibernate.show_sql”设置为 true。找到该设置并将其更改为 false。
I'm fairly certain that you're seeing those SQL statements because somewhere in your Hibernate config the property "hibernate.show_sql" is set to true. Find that setting and change to false.
如果您有 persistence.xml 文件,请尝试那里。我就是在那里找到它的。
If you have a persistence.xml file try there. That's where I found it.
在 applications.properties 文件中将以下设置设置为 false:
它将关闭休眠消息。
Set the below to false in applications.properties file:
it will turn off Hibernation messages.
通过添加解决了这个问题:
在 persistence.xml 文件中,如果您有一个
Solved this by adding:
in the persistence.xml file, this is if you have one
如果您根据配置使用
application.yml
文件,您可能会在jpa
属性下找到属性show-sql:true
。If you are using an
application.yml
file based on your configuration you may find the propertyshow-sql:true
under thejpa
property.对我来说 spring.jpa.show-sql=false 不起作用。
然而,这个人做了一份工作:
For me
spring.jpa.show-sql=false
did not work.However this one did a job: