log4j2 双美元 $$ 符号在配置中的含义

2023-12-24

我正在阅读Log4j2的配置部分。http://logging.apache.org/log4j/2.x/manual/configuration.html http://logging.apache.org/log4j/2.x/manual/configuration.html

<Appenders>
    <Console name="STDOUT">
      <PatternLayout pattern="%m%n"/>
    </Console>
    <List name="List">
      <ThresholdFilter level="debug"/>
    </List>
    <Routing name="Routing">
      <Routes pattern="$${sd:type}">
        <Route>
          <RollingFile name="Rolling-${sd:type}" fileName="${filename}"
                       filePattern="target/rolling1/test1-${sd:type}.%i.log.gz">
            <PatternLayout>
              <pattern>%d %p %c{1.} [%t] %m%n</pattern>
            </PatternLayout>
            <SizeBasedTriggeringPolicy size="500" />
          </RollingFile>
        </Route>
        <Route ref="STDOUT" key="Audit"/>
        <Route ref="List" key="Service"/>
      </Routes>
    </Routing>
  </Appenders>

双$$符号是什么意思?例如$${sd:类型}?


看起来$用作转义字符。如中所述Log4J 文档 http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution、Log4j配置文件解析器使用Apache Commons Lang 的StrSubstitutor http://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/lookup/StrSubstitutor.html,以及本文档StrSubstitutor says:

另一种可能性是使用转义字符,默认为“$”。 如果此字符放置在变量引用之前,则此字符 引用将被忽略并且不会被替换。例如:

The variable $${${name}} must be used.

我猜他们想将值设置为"${sd:type}"以便稍后可以在运行时评估该变量。这里有一个很好的例子/解释:http://logging.apache.org/log4j/2.x/manual/lookups.html#ContextMapLookup http://logging.apache.org/log4j/2.x/manual/lookups.html#ContextMapLookup

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

log4j2 双美元 $$ 符号在配置中的含义 的相关文章

随机推荐