gpt4 book ai didi

java - log4j2 访问 env 属性

转载 作者:行者123 更新时间:2023-11-30 11:10:30 25 4
gpt4 key购买 nike

log4j2文档中提到读取env属性我们必须使用$${env:USERNAME}

我发现带有单个 $${env:USERNAME} 仍然有效。

有谁知道我们为什么要使用$$?!

最佳答案

来自http://logging.apache.org/log4j/2.x/manual/configuration.html手册页:

An interesting feature of StrLookup processing is that when a variable reference is declared with multiple leading '$' characters each time the variable is resolved the leading '$' is simply removed. In the previous example the "Routes" element is capable of resolving the variable at runtime. To allow this the prefix value is specified as a variable with two leading '$' characters. When the configuration file is first processed the first variable is simply removed. Thus, when the Routes element is evaluated at runtime it is the variable declaration "${sd:type}" which causes the event to be inspected for a StructuredDataMessage and if one is present the value of its type attribute to be used as the routing key. Not all elements support resolving variables at runtime. Components that do will specifically call that out in their documentation.

关于java - log4j2 访问 env 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27668212/

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