I use log4j 2 for logging in me application.
I have 3 requirements:
- logs files should consume not more then some amount of disk space - for example 800KB
- size of each logs files should be less then some amount - for example 100KB
- name of each log file should have date in it
Sometimes there would be a lot of logs during the day, sometimes there would be no logs during the day.
So this is example of what I want to see on date 13 september 2022:
- test.log - 0KB
- test-2022-09-12-1.log - 50KB
- test-2022-09-10-1.log - 50KB
- test-2022-09-09-1.log - 50KB
- test-2022-09-09-2.log - 100KB
- test-2022-09-08-1.log - 75KB
- test-2022-09-08-2.log - 100KB
- test-2022-09-08-3.log - 100KB
- test-2022-09-08-4.log - 100KB
- test-2022-09-08-5.log - 100KB
- test-2022-09-07-1.log - 75KB
so together it takes 800KB. And when test.log became no empty, file test-2022-09-07-1.log would be deleted.
I use this configuration:
- name: ErrorLoggerAppender
append: true
filename: '${log-path}/test.log'
filePattern: '${log-path}/test-%d{yyyy-MM-dd}-%i.log'
PatternLayout:
Pattern: 'ERROR >>> %l %n%d{ISO8601} [%m] %n'
Policies:
SizeBasedTriggeringPolicy:
size: 100KB
TimeBasedTriggeringPolicy:
interval: 1
modulate: true
DefaultRolloverStrategy:
max: 20
Delete:
basePath: '${log-path}/'
IfFileName:
glob: '*/*.log'
IfAccumulatedFileSize:
exceeds: 800KB
Filters:
- LevelRangeFilter:
minLevel: ERROR
maxLevel: ERROR
onMatch: ACCEPT
But IfAccumulatedFileSize property doesn't work. 20 log files appear in the directory - each with size of 100KB. And If I remove "max: 20" there would be 7 files because 7 is default.
Is there are something wrong in my configuration? How can I achieve what I want?