Pavan Kemparaju
Pavan Kemparaju

Reputation: 1611

Jetty access logs writing to a .tmp file

Problem I am observing:

At random times of the day, logs start going to .tmp files access.log6732547707051856.tmp (which has logs from 00:00:00 to 00:00:01, this is acceptable I guess when the rollover is happening) and access.log6844458502795078.tmp are two of the files which have logs.

The logger continues to log into the newest tmp file. I have observed a case where it starts writing to the .tmp file at about 6 AM and continues to write there. This stops at the next roll i.e. at 00:00:00 (midnight) where the access.log file is compressed. The .tmp files still remain after this.

  1. Why don't the temp files go away?
  2. Why does it write to the temp files at times when the rollover isn't supposed to happen?

Details of system:

Jetty version I am using: 8.1.15

I am instantiating a new RequestLogHandler with

RequestLogImpl requestLog = new RequestLogImpl();
requestLog.setFileName("logback-access.xml");
requestLogHandler.setRequestLog(requestLog);

The logback-access.xml has

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>/var/log/service/package/access-%d{yyyy-MM-dd}.log.gz</fileNamePattern>
        <maxHistory>10</maxHistory>
    </rollingPolicy>

Upvotes: 1

Views: 1614

Answers (2)

SunilJ
SunilJ

Reputation: 101

My situation is slightly different since I saw tmp files with logback classic 1.1.3 and not logback access.

I am using a Rolling File Appender with a max file size. See my final working config below.

My issue was caused by the difference between

  <appender ..
    <file>${catalina.base}/logs/app-info.log</file>

and

  <appender ...
    <rollingPolicy ...
    <fileNamePattern>logs/app-info-%d{yyyy-MM-dd,UTC}-%i.log.gz</fileNamePattern>

Notice the difference between the 2 file paths. Unlike <file>, <fileNamePattern> does not start with "${catalina.base}/".

Once I made the two paths alike, I stopped seeing new tmp files being generated when logs rolled. Logback now generates the desired log.gz files. Existing tmp files remain as is.

Final working configuration.

<appender name="RollingFile"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${catalina.base}/logs/app-info.log</file>
    <!-- daily rollover -->
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${catalina.base}/logs/app-info-%d{yyyy-MM-dd,UTC}-%i.log.gz</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!--  or whenever the file size reaches 100MB -->
            <maxFileSize>100MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    ...
</appender>

Upvotes: 0

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49515

This is an open bug with the logback implementation, usually seen when rolling is combined with its gzip / compression layer.

Upvotes: 1

Related Questions