简体   繁体   English

如何在Spring Boot控制台中禁用日志

[英]How to disable log in Spring Boot console

I tried to redirect the log output only to a file, but Spring Boot stills logs in console. 我试图将日志输出仅重定向到文件,但是Spring Boot仍然在控制台中记录日志。 Is there any to disable console output? 是否有任何禁用控制台输出的功能?

I set into properties the file name but it does not solved. 我将文件名设置为属性,但没有解决。

###############
### Logging ###
###############
logging.level.=INFO
logging.file=log/${server.context-path}.log

Thanks any help! 谢谢你的帮助!

根据spring boot doc的介绍,您需要提供自己的日志记录配置文件, logging.file将仅将additional日志记录到文件,这是链接: http : //docs.spring.io/spring-boot/docs/current/reference/ HTML / HOWTO-logging.html

I tried removing console configuration from logback.xml. 我尝试从logback.xml中删除控制台配置。 But, It was still logging in console. 但是,它仍在登录控制台。 So What I did is, I just removed the appender being added in the logging configuration by springboot. 所以我要做的是,我删除了springboot在日志配置中添加的appender。 Thereby, we can stop springboot logging in console and separate log file. 因此,我们可以停止在控制台中启动springboot并停止单独的日志文件。 Add the below lines at the end of your application specific appenders are added. 在您的应用程序的末尾添加以下行,并添加特定的附加程序。 Your custom appender should not match any of these appender names. 您的自定义附加程序不应与任何这些附加程序名称匹配。 It worked for me. 它为我工作。

// get instance of your log4j instance
Logger logger = LogManager.getRootLogger();
logger.removeAppender("CONSOLE"); // stops console logging
logger.removeAppender("LOGFILE"); // stops file logging

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

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