简体   繁体   English

在Spring Boot应用程序中动态更改日志记录级别

[英]Change logging level dynamically in spring boot app

I have a spring boot app where I provide logging configuration using 我有一个Spring Boot应用程序,在其中使用以下命令提供日志记录配置

-Dlog4j.configuration=file:E:\workspace\log4j.properties

I am using slf4j for logging. 我正在使用slf4j进行日志记录。 Is there any way in which I can just change "log4j.rootLogger" property and log level can be changed dynamically. 有什么方法可以更改“ log4j.rootLogger”属性,并且可以动态更改日志级别。 If not then what should be the best approach to do that in which I can have minimal change in code. 如果没有,那应该是什么最好的方法呢?在这种方法中,我可以对代码进行最少的更改。 Thanks in advance 提前致谢

You can configure monitorInterval in your log4j configuration: 您可以在log4j配置中配置monitorInterval:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30">
...
</Configuration>

https://logging.apache.org/log4j/2.x/manual/configuration.html https://logging.apache.org/log4j/2.x/manual/configuration.html

Log4j will automatically detect changes to the configuration file and reconfigure itself. Log4j将自动检测对配置文件的更改并重新配置自身。

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

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