简体   繁体   English

如何在运行时更改log4j2的配置文件?

[英]how to change configuration file of log4j2 at runtime?

i would like to turn of my debug statements at runtime in log4j2. 我想在运行时在log4j2中打开我的调试语句。 According to the documentation we can do this. 根据文档,我们可以执行此操作。 I kept my log4j.xml file in default package and then made jar out of it. 我将log4j.xml文件保留在默认软件包中,然后用它制成jar。 Since I cannot modify jar i specified xml file using Dlog4j.configuration=/path/to/log4j.xml. 由于无法修改jar,因此我使用Dlog4j.configuration = / path / to / log4j.xml指定了xml文件。 However,this is not working. 但是,这不起作用。 I Tried everything using file:// uri to all the combination, still it is not picking the xml. 我使用file:// uri对所有组合进行了尝试,但仍然没有选择xml。

The system property to specify the config file location is different from log4j-1.x. 用于指定配置文件位置的系统属性不同于log4j-1.x。 In log4j2, the property is "log4j.configurationFile". 在log4j2中,该属性为“ log4j.configurationFile”。

So if the config is in a jar file you would use: 因此,如果配置位于jar文件中,则可以使用:

-Dlog4j.configurationFile=jar:file:///C:/path/to/jarfile.jar!/path/to/log4j2.xml

(I assume you have the monitorInterval set in your configuration as documented here: http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticReconfiguration ) (我假设您在配置中设置了monitorInterval ,如此处所述: http : //logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticReconfiguration

必须将以下内容添加到配置文件:

<Configuration monitorInterval="60" >

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

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