Why aren’t my Logback Log Files Rolling Over?

It’s probably due to your file name configuration in the appender section of the Logback.xml file. Logback does not like relative file paths! Make sure that both your appender -> file value and the rollingPolicy -> fileNamePattern values have an absolute file path configured. For mine, I used the ${catalina.base} property so that our logs will show up in the tomcat logs directory, regardless of which server the application is deployed to.

...
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- Never use relative paths with logback! -->
        <file>${catalina.base}/logs/my-application.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <!-- Never use relative paths with logback! -->
            <fileNamePattern>${catalina.base}/logs/my-application.%d{yyyy-MM-dd}.log</fileNamePattern>

            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
        </encoder>

    </appender>
...
Advertisements
This entry was posted in Code. Bookmark the permalink.

2 Responses to Why aren’t my Logback Log Files Rolling Over?

  1. Petras says:

    Any news on this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s