Logback: single file with maximum file size

my system support group needs one simple log file with maximum size 10 MB Old log lines can be deleted when the file reaches 10 MB. So expand the oldest lines.

What good is this? I have one appender , but this one still created a second file , and then it starts up again with an empty new file . This is not what my support team wants.

Help is appreciated.

<configuration> <appender name="TEST" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${LOG_HOME}/test.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <fileNamePattern>${LOG_HOME}/test.%i.log</fileNamePattern> <minIndex>1</minIndex> <maxIndex>1</maxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <maxFileSize>10MB</maxFileSize> </triggeringPolicy> <encoder> <pattern>%date %-5level [%thread] - %mdc{loginName} - [%logger]- %msg%n</pattern> </encoder> </appender> <root level="DEBUG"> <appender-ref ref="FILE" /> </root> </configuration> 
+6
source share
1 answer

Saving all in one file and constantly adding the very latest while deleting the oldest lines will be really very bad. I suspect logback cannot be done for this.

I suggest you use a policy based on the normal size, configure it so that it remains within your 10 MB limit, and then just concatenate the files when you capture them.

+4
source

Source: https://habr.com/ru/post/955655/


All Articles