[英]log4j2 and ch.qos.logback.core.PropertyDefinerBase
Logback's PropertyDefinerBase allows to use dynamic properties within logback.xml. Logback的PropertyDefinerBase允许在logback.xml中使用动态属性。 I use this to configure a target directory for a FileAppender with values from my application config.
我用它来配置FileAppender的目标目录,并使用我的应用程序配置中的值。 In my case there's an enum instance that contains the value I want to use:
在我的情况下,有一个包含要使用的值的枚举实例:
public String getPropertyValue() {return MyConfigEnum.LOGDIR.value();}
Relevant parts of logback.xml: logback.xml的相关部分:
<fileNamePattern>${logdir}/test.log</fileNamePattern>
... and: ...和:
<define name="logdir" class="com.example.MyLogdirDefiner" />
This idiom is now needed for log4j 2 . 现在,log4j 2需要这个惯用法。 How can I apply the value of MyConfigEnum.LOGDIR in a log4j2.xml?
如何在log4j2.xml中应用MyConfigEnum.LOGDIR的值?
I don't want to set a property upon application start. 我不想在应用程序启动时设置属性。
Log4j2 also lets you define new properties in the configuration file. Log4j2还允许您在配置文件中定义新属性。
Details are in the Configuration > Property Substitution section of the manual: http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution 详细信息在手册的“配置”>“属性替换”部分中: http : //logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.