通过 maxFileSize 来设置单个日志文件的大小限制。注意到这里,有一个新的标识出现 %i,这是当发生滚动时,可以为同一天的日志加上不同的后缀 index。
配置示例:
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>test.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>foo%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>5MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>
以一个例子来认识 FixedWindowRollingPolicy
Number of rolloversActive output targetActive log filesDescription
First rollover. foo.log is renamed as foo1.log. A new foo.log file is created and becomes the active output target.
Second rollover. foo1.log is renamed as foo2.log. foo.log is renamed as foo1.log. A new foo.log file is created and becomes the active output target.
foo1.log, foo2.log, foo3.log
Third rollover. foo2.log is renamed as foo3.log. foo1.log is renamed as foo2.log. foo.log is renamed as foo1.log. A new foo.log file is created and becomes the active output target.
foo1.log, foo2.log, foo3.log
In this and subsequent rounds, the rollover begins by deleting foo3.log. Other files are renamed by incrementing their index as shown in previous steps. In this and subsequent rollovers, there will be three archive logs and one active log file.
配置示例,一般配合 FixedWindowRollingPolicy:
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-32110-7.html
任何一个门槛低的行业
ipad连热点玩游戏玩的好好的
千玺加油