You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Question:
How to enable dynamic fileName in RollingFileAppender
I have a requirement where i need to create a log file like
server.2024-04-30.log and it has some size based policies when roll over happens the existing file should be renamed to server.2024-04-30.1.log and when the day changes a new file need to be created like server,2024-05-01.log
and when day changes it should be
server.2024-05-01.log
I have tried different approaches
Approach1:
<RollingFilename="FILEC"fileName="${sys:pf.log.dir}/test.${date:yyyy-MM-dd}.log"filePattern="${sys:pf.log.dir}/test.%d{yyyy-MM-dd}.%i.log"ignoreExceptions="false"append="false">
<PatternLayout>
<!-- Uncomment this if you want to use UTF-8 encoding instead of system's default encoding. <charset>UTF-8</charset> -->
<pattern>%d %X{trackingid} %-5p [%c] %replace{%m}{\n}{\\n}%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicysize="100 KB" />
</Policies>
<DefaultRolloverStrategymax="12" />
</RollingFile>
size based rolling is happening fine but when the day changes the fileName was the old date when i have restarted the application, rollover files have correct date as filePattern is working.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Question:
How to enable dynamic fileName in RollingFileAppender
I have a requirement where i need to create a log file like
server.2024-04-30.log and it has some size based policies when roll over happens the existing file should be renamed to server.2024-04-30.1.log and when the day changes a new file need to be created like server,2024-05-01.log
server.2024-04-30.log
server.2024-04-30.1.log
server.2024-04-30.2.log
and when day changes it should be
server.2024-05-01.log
I have tried different approaches
Approach1:
size based rolling is happening fine but when the day changes the fileName was the old date when i have restarted the application, rollover files have correct date as filePattern is working.
Approach2:
followed the discussion on https://issues.apache.org/jira/browse/LOG4J2-1185 and remove the fileName and tried it , log file itself is not getting created
Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions