Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback RollingFileAppender Not Working

I have the following logback.xml file:

<configuration>

    <!--Daily rolling file appender -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>/usr/share/tomcat6/logs/api.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>/usr/share/tomcat6/logs/api/api.%d{yyyy-MM-dd}.gz</FileNamePattern>
        </rollingPolicy>
        <encoder>
          <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>

      <root level="debug">
        <appender-ref ref="FILE" />
        <appender-ref ref="STDOUT" />
      </root>
</configuration>

My log file is working just fine. The folling file aspect however is not. Instead of gzipping the file and moving it into the api folder, it is putting it in the same directory and renaming it to

api.log(string of numbers).tmp

e.g.

api.log849916939395200.tmp

Does anyone know why this is happening?

like image 728
thatidiotguy Avatar asked Sep 13 '13 16:09

thatidiotguy


2 Answers

Just remove the file tag from appender. Use something like this,

<appender name="contentDeliveryLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    <!-- daily rollover -->
    <fileNamePattern>${ICEX_HOME}/logs/content-delivery.%d{yyyy-MM-dd}.log</fileNamePattern>
      <!-- keep 1 days' worth of history -->
      <maxHistory>30</maxHistory>
  </rollingPolicy>
  <encoder>
    <pattern>%d [%thread] %-5level %logger{36} H:${HOSTNAME} - SC:%X{optionalParam} %msg%n</pattern>
  </encoder>
</appender>

This is working for me as recommended by documentation of logback here

like image 187
Prateek Jain Avatar answered Sep 28 '22 12:09

Prateek Jain


I had the similar issue. To fix this issue change the pattern to /usr/share/tomcat6/logs/api/api.%d{yyyy-MM-dd}.%i.gz.

You missed the %i in the end.

like image 28
SANN3 Avatar answered Sep 28 '22 12:09

SANN3