如何配置logback
来更改自动滚动的时间?我在手册中找不到它......这是我的logback.xml片段:
<appender name="data" class="ch.qos.logback.core.FileAppender">
<file>mylog.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>mylog.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
答案 0 :(得分:2)
答案 1 :(得分:-1)
尝试这样做,希望它能为你效劳。
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOGDIR}/filename.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<FileNamePattern>${LOGDIR}/file.%d{yyyy-MM-dd}.%i.log.gz
</FileNamePattern>
<!-- keep 30 days' worth of history -->
<MaxHistory>30</MaxHistory>
<!-- or whenever the file size reaches 10MB -->
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%date [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
以上代码将在当天压缩您的文件或如果日志文件大小超过10MB。
注意:我在filePattern中添加了“%i”,它会将文件名重复为file1,file2等。