'What is the Log4j2 syntax especially for the 2nd part of the name?
I have not been able to find the syntax for setting up the configuration file. Granted it is working but unable to find an explanation of the 2nd item.
For example, I see plenty of samples like this and it works.
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
But I also see samples like this and it works too.
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
Originally it seemed like rolling was the actual 2nd item
logger.rolling.someProperty
But it really seems like the 2nd item can be just about anything.
logger.anyValue.someProperty
Is there a link to discuss this 2nd item and acceptable values along with when it needs to possible match?
Solution 1:[1]
The best reference for the properties configuration format is of course the source code.
The nature of a Log4j2 configuration is hierarchical (as expressed in the default XML configuration format), while the properties format is flat. Therefore whenever the Log4j2 syntax allows for multiple components of the same type, the properties of each component must be prefixed by a unique identifier. The only restriction on the identifier is that it can not contain a dot .. You can think of these identifiers as of the splinters you obtain from putting a square peg into a round hole, no other Log4j2 configuration format has them.
For example if in your XML configuration you have:
<Loggers>
<Logger name="org.apache.logging.log4j" level="INFO" />
<Logger name="org.apache.logging.log4j.core" level="DEBUG" />
</Loggers>
to translate it to the properties format you need to choose two identifiers, let's say <1> and <2> and you obtain:
logger.<1>.name = org.apache.logging.log4j
logger.<1>.level = INFO
logger.<2>.name = org.apache.logging.log4j.core
logger.<2>.level = DEBUG
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Piotr P. Karwasz |
