最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Logback not compressing sparse logs when app restarts often - Stack Overflow

programmeradmin7浏览0评论

My app logging with logback does not compress my log into the configured .gz file.

This is a fairly sparse audit log, which during quiet periods is only written once or twice per hour. I suspect, because we deploy many times a day, it can happen that the application is redeployed before an event triggering log rollover arrives and I end up with files not being compressed.

The appender is configured to roll every hour:

<appender name="AUDIT-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_ROOT}/audit/%d{yyyy-MM, UTC, aux}/%d{yyyy-MM-dd_HH, UTC}-service-audit.log.gz</fileNamePattern>
    </rollingPolicy>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %msg%n</pattern>
    </encoder>
</appender>

The configuration is picked up correctly:

INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [AUDIT-FILE]
INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
INFO in ch.qos.logback.core.model.processor.ModelInterpretationContext@4b741d6d - value "/opt/sf/logs/audit/%d{yyyy-MM, UTC, aux}/%d{yyyy-MM-dd_HH, UTC}-service-audit.log.gz" substituted for "${LOG_ROOT}/audit/%d{yyyy-MM, UTC, aux}/%d{yyyy-MM-dd_HH, UTC}-service-audit.log.gz"
INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1856158867 - Will use gz compression
INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1856158867 - Will use the pattern /opt/sf/logs/audit/%d{yyyy-MM, UTC, aux}/%d{yyyy-MM-dd_HH, UTC}-service-audit.log for the active file
INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd_HH' from file name pattern '/opt/sf/logs/audit/%d{yyyy-MM, UTC, aux}/%d{yyyy-MM-dd_HH, UTC}-service-audit.log.gz'.
INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at the top of every hour.
INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to 2025-03-25T17:28:48.413Z
INFO in ch.qos.logback.core.rolling.RollingFileAppender[AUDIT-FILE] - Active log file name: /opt/sf/logs/audit/2025-03/2025-03-25_17-service-audit.log
NFO in ch.qos.logback.core.rolling.RollingFileAppender[AUDIT-FILE] - File property is set to [null]

Is this expected behaviour? Is there a way around it to force logback to compress files which missed their rollover?

发布评论

评论列表(0)

  1. 暂无评论