对Logback Appender类属性使用变量替代 [英] Use Variable Substitution for Logback Appender Class Attribute

查看:73
本文介绍了对Logback Appender类属性使用变量替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为Logback附加程序指定实现类时,是否可以使用变量替换?例如,

Is it possible to use variable substitution when specifying the implementing class for a Logback appender? e.g.,

<appender name="LOGFILE" class="${LOGFILE_APPENDER_CLASS}">

如上指定时,Logback似乎试图加载名称为"$ {LOGFILE_APPENDER_CLASS}"的类.即不执行任何变量替换!

When specified as above, Logback appears to attempt to load a class with a name of "${LOGFILE_APPENDER_CLASS}". i.e., no variable substitution is performed!

21:17:11,331 | -INFO |即将实例化类型[$ {LOGFILE_APPENDER_CLASS}]的附加程序21:17:11,333 | -ch.qos.logback.core.joran.action.AppenderAction中发生错误-无法创建类型为[$ {LOGFILE_APPENDER_CLASS}]的Appender.ch.qos.logback.core.util.DynamicClassLoadingException:无法实例化类型$ {LOGFILE_APPENDER_CLASS}在ch.qos.logback.core.util.DynamicClassLoadingException处:无法实例化类型$ {LOGFILE_APPENDER_CLASS}

我想将输出发送到Eclipse开发人员的生产和控制台文件中.如果可能的话,我不想重复该配置器,因为它包含一长串的过滤器,在大多数情况下都是相同的.

I want to send output to a file in production and console for eclipse developers. I don't want to duplicate the appender configuration if possible as it contains a long list of filters that will be the same in most cases.

推荐答案

根据问题,所有证据表明LogBack在这种情况下不会执行变量替换.

As per the question, all evidence indicates that LogBack will not perform variable substitution in this scenario.

采用的解决方案是从XML配置文件切换到Groovy配置文件.然后根据从环境派生的"bDeveloper"变量动态控制附加程序列表.

Adopted solution was to switch from XML configuration file to Groovy configuration file. Then dynamically control the list of appenders based on a "bDeveloper" variable derived from the environment.

def bDeveloper = ["","true"].contains("${System.getProperty("developer")}".toLowerCase())
if (bDeveloper) {
    scan("15 seconds")
    lstRootAppenders.add("BEAGLE")
    oLogfileAppender = ch.qos.logback.core.ConsoleAppender
}

这篇关于对Logback Appender类属性使用变量替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆