简体   繁体   English

log4j2和ch.qos.logback.core.PropertyDefinerBase

[英]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.

相关问题 ClassCastException:org.slf4j.impl.Log4jLoggerAdapter无法转换为ch.qos.logback.classic.Logger - ClassCastException: org.slf4j.impl.Log4jLoggerAdapter cannot be cast to ch.qos.logback.classic.Logger Logback中的Log4j2标记 - Log4j2 markers in Logback 使用log4j2和logback - Using log4j2 and logback ch.qos.logback.core.util.DynamicClassLoadingException:无法实例化类型ch.qos.logback.classic.net.SMTPAppender - ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.net.SMTPAppender Sbt test: class org.apache.logging.slf4j.Log4jLogger cannot be cast to class ch.qos.logback.classic.Logger (org.apache.logging.slf4j.Log4jLogger - Sbt test: class org.apache.logging.slf4j.Log4jLogger cannot be cast to class ch.qos.logback.classic.Logger (org.apache.logging.slf4j.Log4jLogger 如何解决 log4j2 和 logback 冲突? - how to solve the log4j2 and the logback confliction? org.slf4j.helpers.SubstituteLogger 不能转换为 ch.qos.logback.classic.Logger - org.slf4j.helpers.SubstituteLogger cannot be cast to ch.qos.logback.classic.Logger 类 ch.qos.logback.classic.LoggerContext 没有实现请求的接口 org.slf4j.ILoggerFactory - Class ch.qos.logback.classic.LoggerContext does not implement the requested interface org.slf4j.ILoggerFactory ClassCaseException org.slf4j.impl.SimpleLoggerFactory 无法转换为 ch.qos.logback.classic.LoggerContext - ClassCaseException org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext 连接Cassandra DB时java.lang.NoClassDefFoundError:ch / qos / logback / core / joran / spi / JoranException - java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException while connecting Cassandra DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM