Java 如何在 spring-boot 中禁用控制台日志记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43918414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable console logging in spring-boot?
提问by membersound
I'm using the default logging configuration of spring-boot.
我正在使用spring-boot的默认日志记录配置。
How can I prevent the console output, while keeping the logging into a logfile configured with logging.file=myfile.log
?
如何防止控制台输出,同时保持登录到配置的日志文件logging.file=myfile.log
?
My goal is to not having console windows output, but only logging to that file.
我的目标是没有控制台窗口输出,而只记录到该文件。
Without having to create a specific logback.xml
configuration. Because I'm using spring-boot
for not having to configure the logging myself.
无需创建特定logback.xml
配置。因为我使用的spring-boot
是不必自己配置日志记录。
采纳答案by membersound
It turned out if I set the following property empty, the console logging is disabled:
事实证明,如果我将以下属性设置为空,控制台日志记录将被禁用:
logging.pattern.console=
logging.pattern.console=
Or commenting in xml if you use it
或者如果你使用它在xml中评论
<!--<root level="error">-->
<!--<appender-ref ref="console"/>-->
<!--</root>-->
回答by Daniel
All the supported logging systems can have the logger levels set in the Spring Environment using ‘logging.level.*=LEVEL' where ‘LEVEL' is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. The root logger can be configured using logging.level.root
. Example application.properties:
所有支持的日志系统都可以在 Spring Environment 中使用 'logging.level.*=LEVEL' 设置记录器级别,其中 'LEVEL' 是 TRACE、DEBUG、INFO、WARN、ERROR、FATAL、OFF 之一。可以使用logging.level.root
. 示例 application.properties:
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
Check this information: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html
检查此信息:https: //docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html
You could also overwrite the logback
configuration and provide the value OFF
to it.
您还可以覆盖logback
配置并为其提供值OFF
。
<configuration>
<!-- turn OFF all logging (children can override) -->
<root level="OFF">
<appender-ref ref="STDOUT" />
</root>
</configuration>
You can find more information at the following link: https://logback.qos.ch/manual/configuration.html#rootElement
您可以在以下链接中找到更多信息:https: //logback.qos.ch/manual/configuration.html#rootElement
回答by Hymanson Cassimiro
I created a file called logback.xml with the content:
我创建了一个名为 logback.xml 的文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework" level="ERROR"/>
<logger name="org.hibernate" level="ERROR"/>
</configuration>
See this link for more information: https://www.mkyong.com/spring-boot/spring-boot-test-how-to-stop-debug-logs/
有关更多信息,请参阅此链接:https: //www.mkyong.com/spring-boot/spring-boot-test-how-to-stop-debug-logs/