Apache Log4j2的StrSubstitutor中的”default variable”不起作用。

huangapple go评论73阅读模式
英文:

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:

&lt;Property name=&quot;defaultCatalinaRootpath&quot;&gt;${sys:catalina.home}/webapps/${contextName}/logs/&lt;/Property&gt;
&lt;Property name=&quot;logDir&quot;&gt;${bundle:logger:userRootpath:-${defaultCatalinaRootpath}}&lt;/Property&gt;

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...

&lt;Property name=&quot;logDir&quot;&gt;${bundle:logger:userRootpath}&lt;/Property&gt;

...or this...

&lt;Property name=&quot;logDir&quot;&gt;${sys:catalina.home}/webapps/${contextName}/logs/&lt;/Property&gt;

...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.

huangapple
  • 本文由 发表于 2020年8月20日 15:08:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63499944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定