Spring Boot和Logback:禁用记录器 [英] Spring Boot and Logback: Disable a logger
问题描述
使用Spring Boot 1.4和Logback,我在 application.yml
中配置日志记录:
Using Spring Boot 1.4 together with Logback, I configure the logging in the application.yml
:
logging:
level:
org.hibernate.SQL: INFO
com.netflix.eureka: OFF
请注意,第二种配置的建议直接来自 Spring Cloud Service注册和发现文档.它适用于 INFO 和其他正常"级别.但是,日志还会显示(由我重新格式化):
Note that the recommendation for the second configuration comes straight from the Spring Cloud Service Registration and Discovery documentation. It works quite well for INFO and other ‘normal’ levels. However, the log also shows (reformatted by me):
… o.s.cloud.logging.LoggingRebinder : Cannot set level: false for
'org.hibernate.engine.internal.StatisticalLoggingSessionEventListener'
现在, false
是一个非常有趣的级别,不是吗?如何完全禁用记录器?
Now, false
is a very interesting level, isn’t it? How can I disable a logger completely?
推荐答案
yaml-parser将 OFF
和 ON
解释为 Boolean
因此将 false
或 true
传递给日志记录框架.如果要禁用级别为 OFF
的日志记录,则需要将属性的值设置为 String
,这可以通过单引号将其实现.您的示例已修改:
The yaml-parser interprets the words OFF
and ON
as Boolean
and so passes false
or true
to the logging framework.
If you want to disable logging with the level OFF
you need to set the value of the property as a String
which can be achieved by single quotes.
Your example modified:
logging:
level:
org.hibernate.SQL: INFO
com.netflix.eureka: 'OFF'
这篇关于Spring Boot和Logback:禁用记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!