gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 02:38:48 25 4
gpt4 key购买 nike

我正在阅读 Log4j2 的配置部分。 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:type}?

最佳答案

好像是用$作为转义字符。如 Log4J documentation 中所述, Log4j 配置文件解析器使用Apache Commons Lang's StrSubstitutor ,而这个 StrSubstitutor 的文档说:

The other possibility is to use the escape character, by default '$'. If this character is placed before a variable reference, this reference is ignored and won't be replaced. For example:

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

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

关于java - log4j2 双美元 $$ 符号在配置中的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39393393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com