Reputation: 131
I use tomcat 9.0,slf4j for logging. The problem was that log files are too big(17GM - the max i saw). I created java-based deleting system for logs. Because tomcat creates new log file every day. But here is one unexpected moment. Tomcat creates log files whenever it may, sometimes it may use old days file. For example today is 16th. This file may be used till 18th. And thats why the size becomes big. Even if configure correct(for my case) log creation i may have logs for 2 days in one file. For example from 16th 1:00 pm till 17th 12:00 am.
So, i want to configure rotation for somehow. Can somebody help?
Upvotes: 0
Views: 3605
Reputation: 1124
slf4j is just an interface, you must be using log4j, logback, common-logging, etc (implmentation of slf4j).
If you are using slf4j + logback, you can set your rollingPolicy in logback.xml file. It cab be TimeBasedRollingPolicy, Size or combination of both.
For example, to set Time based policy to create log file per day and move older files to archive folder and just keep last 30 days logs, you can add this in your logback.xml file
<appender name="app" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.home}/logs/appname/app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.home}/logs/archive/appname/app.%d{yyyy-MM-dd}.old.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>[%X{key}]%date{"yyyy-MM-dd'T'HH:mm:ss,SSSXXX", UTC} %-5level %logger{35}.%M[%L]-[%t] - %msg %n</pattern>
</encoder>
Upvotes: 1