ppkarwasz commented on issue #1561:
URL:
https://github.com/apache/logging-log4j2/issues/1561#issuecomment-1640231171
Hi testcloud2023,
On Tue, 18 Jul 2023 at 10:01, testcloud2023 ***@***.***>
wrote:
> I am using log4j2 version 2.17.1 and I am unable to have with this setting
> in log4j.xml :
>
> <RollingFile name="EVENT_LOG_FILE"
fileName="${path}/kpi/${logNamePrefix}_events-${date:yyyy-MM-dd}.log"
>
filePattern="${path}/kpi/${logNamePrefix}_events-%d{yyyy-MM-dd}.log">
> <Policies>
> <TimeBasedTriggeringPolicy/>
> </Policies>
> <PatternLayout pattern="TSL=%d{yyyyMMdd:HH:mm:ss.SS'Z'},%m%n"
/>
> </RollingFile>
>
> the current date file named with the current date.
>
I answered to your question on StackOverflow[1], but I copy the answer here
for completeness' sake:
**TL;DR**: Remove the `fileName` attribute from your configuration and it
will work as requested.
The rolling file appender has two rollover strategies[2]:
* the `DefaultRolloverStrategy`[3] is useful when the current log file and
the archived ones follow a **different** naming convention. To enable it
you need to specify both `fileName` and `filePattern`.
* the `DirectWriteRolloverStrategy`[4] is useful when all the log files
follow a common naming convention, which is your case. To enable this
strategy you need to omit the `fileName` attribute.
What happens in your case is that you provide both `fileName` and
`filePattern`. The `${...}` lookups are resolved at **configuration** time
(which happened on July, 7th). After the initial interpolation of your
configuration their values are:
* `fileName=".../kpi/prefix_events-2023-07-07.log"`
* `filePattern=".../kpi/prefix_events-%d{yyyy-MM-dd}.log"`
At each rollover the current file `prefix_events-2023-07-07.log` is moved
to the file corresponding to the current date.
Piotr
[1] https://stackoverflow.com/q/76706536/11748454
[2]
https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/rolling/RolloverStrategy.html
[3]
https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.html
[4]
https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.html
> Message ID: ***@***.***>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]