I found some predefined fileNamePatterns for TimeBasedRollingPolicy.

Here's one that does every minute.

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logfile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">      
      <fileNamePattern>logfile.%d{yyyy-MM-dd_HH-mm}.log</fileNamePattern>
    </rollingPolicy>
  </appender>

Does anyone know how do i do this for every x days?

Could I extend RollingFileAppender? I am doing this in Scala.

有帮助吗?

解决方案

Regardless of using Scala or Java, the answer is easy for x == 1 and x == 7.

For daily rollover, use

<fileNamePattern>logfile.%d{yyyy-MM-dd}.log</fileNamePattern>

and for weekly, write

<fileNamePattern>logfile.%d{yyyy-ww}.log</fileNamePattern>

(actually it rolls over at the start of the week depending on your locale, and not every seven days).

If you want a more general solution, you have to implement your custom RollingPolicy, but I don't know why would you need that. If you have problems with this size of the log, you should note that the log can be rolled over when a a specific size is reached. There are plenty of examples at http://logback.qos.ch/manual/appenders.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top