Question

I am using slf4j with scala. Is there a way to rotate logs?

I am trying to clear the log every 7 days. Or in other words, empty out the log file every 7 days.

Was it helpful?

Solution 2

For a ch.qos.logback.core.rolling.RollingFileAppender add the following rolling policy:

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    <!-- daily rollover -->
    <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
    <!-- keep 7 days' worth of history -->
    <maxHistory>7</maxHistory>
</rollingPolicy>

No need for any external solutions, logback will take care of your logging history for you. For this and other information, the logback manual is always a good source.

OTHER TIPS

For linux - logrotate is a popular solution

Add your log rotation config to the following directory:

/etc/logrotate.d/

/var/log/your.log {
  missingok
  notifempty
  size 30k
  weekly
  create 0600 root root
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top