仅根据文件大小进行回滚 [英] Logback roll only on file size
问题描述
我正在使用logback 1.0.13.我希望我的日志文件仅根据文件大小滚动.如果这需要2个小时或2年,我不在乎.我在弄清楚该怎么做时遇到麻烦.我的附加程序的配置如下:
I am using logback 1.0.13. I want my log file to roll solely based off of file size. If this takes 2 hours or 2 years, I don't care. I am having trouble figuring out how to do so. My appender is configured like so:
<appender name="serverFaultFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/folder/to/log/file.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/folder/to/log/file-%d{yyyy-MM}.%i.log</fileNamePattern>
<MaxHistory>2</MaxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
<MaxHistory>9</MaxHistory>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>[%p] [%d{ISO8601}] [%c] [%m]%n</pattern>
</encoder>
</appender>
此解决方案每月推出一次,这不是我所需要的.我尝试完全删除-%d {dateformat}修饰符,但随后甚至从未创建/记录该文件.我尝试使用修饰符%G和%yyyy,但每月的粒度与logback显然可以使我获得(请参阅
This solution rolls monthly, which isn't what I need. I tried completely dropping the -%d{dateformat} modifier, but then the file was never even created/logged to. I tried modifiers %G and %yyyy, but monthly was as fine grained as logback would apparently allow me to get (see this bug report). What am I missing?
推荐答案
你想要一个 SizeBasedTriggeringPolicy: http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy ,可能与FixedWindowRollingPolicy结合使用.
You want a SizeBasedTriggeringPolicy: http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy, probably combined with a FixedWindowRollingPolicy.
以前曾有评论,但不确定它是否值得自己回答,但确实如此.;)
Was a comment before, not sure it deserves it's own answer, but here it is. ;)
这篇关于仅根据文件大小进行回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!