简体   繁体   English

如何以编程方式更改log4j2中的日志级别

[英]How to change programatically log level in log4j2

I need to change programatically log level in log4j2 in my application. 我需要在我的应用程序中以编程方式更改log4j2中的日志级别。 I know that there are several options for this: 我知道有几种选择:

  1. Relying on core log4j classes 依靠核心log4j类
  2. Using JConsole 使用JConsole

Are there any solution to change log level without relying on core classes? 有什么解决方案可以在不依赖核心类的情况下更改日志级别? JConsole is also isn't an option as I need to change it directly from my application. JConsole也不是一个选项,因为我需要直接从我的应用程序中对其进行更改。

There are no methods in log4j-api to change the log level of a logger or an appender. log4j-api中没有方法可以更改记录器或附加器的日志级别。

The cleanest way to do this is via JMX. 最干净的方法是通过JMX。 Look at the source code for log4j-jmx to see how the log4j JMX client does this and then imitate this in your application. 查看log4j-jmx的源代码,以了解log4j JMX客户端如何做到这一点,然后在您的应用程序中模仿它。

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

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