英文:
Apache Log4j2 StrSubstitutor "default variable" does not work
问题
我正在尝试配置log4j2记录器。它使用Apache StringSubstitutor。
我想将默认的根目录设置为"${sys:catalina.home}/webapps/${contextName}/logs/"。如果在logger.properties文件中设置了属性"userRootpath",则应用程序应该使用它。我将它设置为"${bundle:logger:userRootpath}"。
为了实现这一点,我试图使用描述在这里的":-变量默认值分隔符"。但如果我将它设置为以下内容,它就不起作用:
<Property name="defaultCatalinaRootpath">${sys:catalina.home}/webapps/${contextName}/logs/</Property>
<Property name="logDir">${bundle:logger:userRootpath:-${defaultCatalinaRootpath}}</Property>
它总是只取${defaultCatalinaRootpath},从不考虑${bundle:logger:userRootpath},尽管它已在logger.properties中设置。
如果我像这样设置目录...
<Property name="logDir">${bundle:logger:userRootpath}</Property>
...或者像这样...
<Property name="logDir">${sys:catalina.home}/webapps/${contextName}/logs/</Property>
...它可以工作,所以问题不在于属性初始化损坏。
我尝试以不同的方式在":-"结构内初始化属性,但对我来说都不起作用。
我如何实现所需的行为?
英文:
I am trying to configure log4j2 logger. It uses Apache StringSubstitutor.
I want to set default root directory as "${sys:catalina.home}/webapps/${contextName}/logs/". And if property "userRootpath" has been set in logger.properties file, app should use it. I set it as "${bundle:logger:userRootpath}".
To implement this I'm trying to use ":-" variable default value delimiter which described here.
But it does not work if I set it as:
<Property name="defaultCatalinaRootpath">${sys:catalina.home}/webapps/${contextName}/logs/</Property>
<Property name="logDir">${bundle:logger:userRootpath:-${defaultCatalinaRootpath}}</Property>
It always just takes ${defaultCatalinaRootpath} and never consider ${bundle:logger:userRootpath} although it has been set in logger.propeties.
If I set directory like this...
<Property name="logDir">${bundle:logger:userRootpath}</Property>
...or this...
<Property name="logDir">${sys:catalina.home}/webapps/${contextName}/logs/</Property>
...it works, so the case is not about corrupted properties initialization.
I tried to initialize properties in different ways inside ":-" structure, but nothing works for me.
How can I achieve desired behavior?
答案1
得分: 0
经过一些调试,我认为这是一个错误,特指在":-"结构内的捆绑变量,我在这里报告了它:https://issues.apache.org/jira/browse/LOG4J2-2913
如果你有一些绕过的方法,请分享,我将不胜感激。
英文:
After some debug I consider this is a bug, specified for bundle variables inside ":-" structure, I reported it here: https://issues.apache.org/jira/browse/LOG4J2-2913
If you have some ideas how to get around, please share, I would be grateful.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论