名称第二部分的 Log4j2 语法是什么?

What is the Log4j2 syntax especially for the 2nd part of the name?

我找不到设置配置文件的语法。 当然它正在工作,但无法找到第二项的解释。

例如,我看到很多这样的示例并且它有效。

log4j2.properties
name = PropertiesConfig
 
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${LOG_DIR}/application.log
appender.rolling.filePattern = ${LOG_DIR}/application.%d{dd-MMM}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 5
 
logger.rolling.name = rollingFile
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile

但我也看到了这样的示例,它也有效。

log4j2.properties
name = PropertiesConfig
 
appender.rolling5.type = RollingFile
appender.rolling5.name = RollingFile
appender.rolling5.fileName = ${LOG_DIR}/application.log
appender.rolling5.filePattern = ${LOG_DIR}/application.%d{dd-MMM}.log.gz
appender.rolling5.layout.type = PatternLayout
appender.rolling5.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
appender.rolling5.policies.type = Policies
appender.rolling5.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling5.policies.size.size=10MB
appender.rolling5.strategy.type = DefaultRolloverStrategy
appender.rolling5.strategy.max = 5
 
logger.rolling3.name = rollingFile
logger.rolling3.level = debug
logger.rolling3.additivity = false
logger.rolling3.appenderRef.rolling.ref = RollingFile

最初看起来 滚动 是实际的第二项

logger.rolling.someProperty

但第二项似乎真的可以是任何东西。

logger.anyValue.someProperty

是否有 link 来讨论第二项和可接受的值以及何时需要匹配?

属性配置格式最好的参考当然是source code.

Log4j2 配置的本质是分层的(以默认 XML 配置格式表示),而属性格式是扁平的。因此,每当 Log4j2 语法允许同一类型的多个组件时,每个组件的属性都必须以唯一标识符为前缀。标识符的唯一限制是它不能包含点 .。您可以将这些标识符看作是将方钉插入圆孔中得到的碎片,其他 Log4j2 配置格式都没有它们。

例如,如果在您的 XML 配置中,您有:

<Loggers>
    <Logger name="org.apache.logging.log4j" level="INFO" />
    <Logger name="org.apache.logging.log4j.core" level="DEBUG" />
</Loggers>

要将其转换为属性格式,您需要选择两个标识符,比方说 <1><2>,您将获得:

logger.<1>.name = org.apache.logging.log4j
logger.<1>.level = INFO
logger.<2>.name = org.apache.logging.log4j.core
logger.<2>.level = DEBUG