Answering this this question about log4j2 left me more confused than enlightened.
There seem to be several ways of specifying the current date (with custom format) in log4j2 configuration files:
(Interestingly, the log4j2 docs consistently use $${date:...}
in their examples, but doubling the dollar character should escape it and make it a literal dollar character followed by a curly brace and the word "date", a colon, the format, and the closing brace.)
What's the difference between one form or the other, if there is a difference? When should one used over the other?
Is there a difference when used together in a single value? The examples contain the following:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Properties>
<Property name="baseDir">logs</Property>
</Properties>
<Appenders>
<!-- HERE: -->
<RollingFile name="RollingFile" fileName="${baseDir}/app.log"
filePattern="${baseDir}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n" />
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<DefaultRolloverStrategy>
<Delete basePath="${baseDir}" maxDepth="2">
<IfFileName glob="*/app-*.log.gz" />
<IfLastModified age="P60D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
- Why the double dollar in front of
$${date:yyyy-MM}
, but only a single dollar with${baseDir}
? - Why
${date:yyyy-MM}
and%d{MM-dd-yyyy}
and not%d{yyyy-MM}
or${date:MM-dd-yyyy}
?
Who can clear the confusion?