Log4j2.properties not keeping more than 7 files in the log despite exceed number set much higher

36 views Asked by At

I want to limit the total size of the logs of artemis.

I succeeded when I had set the number to 7.

But for some reason now it is not working when i set it to higher value.

total 78804
-rw-rw-r--+ 1 vagrant 101  7231169 Mar 22 18:14 artemis.log
-rw-rw-r--+ 1 vagrant 101 10486161 Mar 22 18:13 artemis.log.2024-03-22.1
-rw-rw-r--+ 1 vagrant 101 10488879 Mar 22 18:13 artemis.log.2024-03-22.2
-rw-rw-r--+ 1 vagrant 101 10488369 Mar 22 18:13 artemis.log.2024-03-22.3
-rw-rw-r--+ 1 vagrant 101 10488293 Mar 22 18:13 artemis.log.2024-03-22.4
-rw-rw-r--+ 1 vagrant 101 10489769 Mar 22 18:13 artemis.log.2024-03-22.5
-rw-rw-r--+ 1 vagrant 101 10487829 Mar 22 18:14 artemis.log.2024-03-22.6
-rw-rw-r--+ 1 vagrant 101 10488914 Mar 22 18:14 artemis.log.2024-03-22.7

This is how I configured the properties in log4j2.properties in etc in the volume.

# Log file appender
appender.log_file.type = RollingFile
appender.log_file.name = log_file
appender.log_file.fileName = .../log/artemis.log
appender.log_file.filePattern = .../log/artemis.log.%d{yyyy-MM-dd}.%i
appender.log_file.layout.type = PatternLayout
appender.log_file.layout.pattern = %d %-5level [%logger] %msg%n
appender.log_file.policies.type = Policies
appender.log_file.policies.size.type = SizeBasedTriggeringPolicy
appender.log_file.policies.size.size = 10MB
appender.log_file.strategy.type = DefaultRolloverStrategy
appender.log_file.strategy.delete.type = Delete
appender.log_file.strategy.delete.basePath = .../log/
appender.log_file.strategy.delete.maxDepth = 1
appender.log_file.strategy.delete.ifAccumulatedFileCount.type = IfAccumulatedFileCount
appender.log_file.strategy.delete.ifAccumulatedFileCount.exceeds = 20

When I was initially trying it out i had set the exceeds to 7 and it was working fine. I thought it would work fine with 10 or 20 as well but it doesn't. It gets stuck at 7. When I tried giving the value 5 it worked fine.

I then thought maybe it uses only single digits, but when I gave 9 it again got stuck till 7. Very confusing issue.

And I am sure this is the right log4j2.properties file, because when I change the filePattern for example adding an infix, it becomes visible in real time. No container restart is necessary.

I verified that the right log4j2.properties was being referenced by changing the exceeds value, and the filePattern to check if it would affect the created files.

The changes occur quite often because it splits the log file every time 10mb worth of data have been created.

It also seems, based on the movement of the files size, that as soon as the new file is written as 7, all others are renamed (I think) to 6, 5, 4 ... and so on until 1 and then the previous one is deleted

0

There are 0 answers