slf4j logback日志滚动创建.tmp文件

huangapple go评论70阅读模式
英文:

slf4j logback log rolling creating .tmp file

问题

我有一个问题,有时日志滚动会创建一个.tmp文件,并且不会创建原始的日志文件。有趣的是,我注意到这种情况发生在日志滚动在午夜前1分钟开始时。

<slf4j.version>1.7.15</slf4j.version>

我的logback.xml配置如下:

    &lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;
        &lt;File&gt;${COMPONENT_LOGDIR}/abc.log&lt;/File&gt;
        &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.TimeBasedRollingPolicy&quot;&gt;
            &lt;fileNamePattern&gt;${COMPONENT_LOGDIR}/abc.log.%d{yyyy-MM-dd}.%i.gz&lt;/fileNamePattern&gt;

            &lt;timeBasedFileNamingAndTriggeringPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP&quot;&gt;
                &lt;maxFileSize&gt;750MB&lt;/maxFileSize&gt;
            &lt;/timeBasedFileNamingAndTriggeringPolicy&gt;
            &lt;maxHistory&gt;10&lt;/maxHistory&gt;
        &lt;/rollingPolicy&gt;
        &lt;encoder&gt;
            &lt;pattern&gt;${logPatternMdc}&lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;
英文:

I have a issue where sometime log rolling creating a .tmp file and does not create the original log file back. interesting I noticed this happens when rolling of logs start 1 min before the midnight.

<slf4j.version>1.7.15</slf4j.version>

my logback.xml configuration is as below

    &lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;
        &lt;File&gt;${COMPONENT_LOGDIR}/abc.log&lt;/File&gt;
        &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.TimeBasedRollingPolicy&quot;&gt;
            &lt;fileNamePattern&gt;${COMPONENT_LOGDIR}/abc.log.%d{yyyy-MM-dd}.%i.gz&lt;/fileNamePattern&gt;

            &lt;timeBasedFileNamingAndTriggeringPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP&quot;&gt;
                &lt;maxFileSize&gt;750MB&lt;/maxFileSize&gt;
            &lt;/timeBasedFileNamingAndTriggeringPolicy&gt;
            &lt;maxHistory&gt;10&lt;/maxHistory&gt;
        &lt;/rollingPolicy&gt;
        &lt;encoder&gt;
            &lt;pattern&gt;${logPatternMdc}&lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;

答案1

得分: 0

&lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;
    &lt;File&gt;${COMPONENT_LOGDIR}/otm-rest.log&lt;/File&gt;
    &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy&quot;&gt;
        &lt;fileNamePattern&gt;${COMPONENT_LOGDIR}/otm-rest.log.%d{yyyy-MM-dd}.%i.gz&lt;/fileNamePattern&gt;
        &lt;maxFileSize&gt;750MB&lt;/maxFileSize&gt;
        &lt;maxHistory&gt;30&lt;/maxHistory&gt;
        &lt;totalSizeCap&gt;15GB&lt;/totalSizeCap&gt;
    &lt;/rollingPolicy&gt;
    &lt;encoder&gt;
        &lt;pattern&gt;${logPatternMdc}&lt;/pattern&gt;
    &lt;/encoder&gt;
&lt;/appender&gt;
英文:

Using different rolling policy seemed to have fixed the issue. please refer to working config below:

&lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;
    &lt;File&gt;${COMPONENT_LOGDIR}/otm-rest.log&lt;/File&gt;
    &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy&quot;&gt;
        &lt;fileNamePattern&gt;${COMPONENT_LOGDIR}/otm-rest.log.%d{yyyy-MM-dd}.%i.gz&lt;/fileNamePattern&gt;
            &lt;maxFileSize&gt;750MB&lt;/maxFileSize&gt;
            &lt;maxHistory&gt;30&lt;/maxHistory&gt;
            &lt;totalSizeCap&gt;15GB&lt;/totalSizeCap&gt;
    &lt;/rollingPolicy&gt;
    &lt;encoder&gt;
        &lt;pattern&gt;${logPatternMdc}&lt;/pattern&gt;
    &lt;/encoder&gt;
&lt;/appender&gt;

huangapple
  • 本文由 发表于 2020年4月7日 10:43:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/61072004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定