views:

53

answers:

1

Sometimes when I launch my java application, logback refuses to write anything to my logfile. Sometimes it also refuses to roll the logfile at midnight (or at the first logging event after midnight), which results in logging events being lost to the void. When i look at my main log file when logbacks has failed to roll the log, it will have a time like 23:59, with yesterday's date, and any and all logging statements after that time will be irretrievably lost. I have a fairly simple configuration file, and it looks correct. It certainly should be correct, as it works most of the time.

Here's my configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <!--See http://logback.qos.ch/manual/appenders.html#RollingFileAppender--&gt;
    <!--and http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy--&gt;
    <!--for further documentation-->
    <append>true</append>
    <File>aggregator.log</File>
    <encoder>
        <!-- was: %d{yyyy-MM-dd HH:mm:ss}%5p [%t] (%F:%L) - %msg%n -->
      <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] \(%class{25}:%line\) - %msg%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- By setting the name to .gz here, we get free compression. -->
      <fileNamePattern>aggregator.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
    </rollingPolicy>
  </appender>
  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] \(%class{25}:%line\) - %msg%n</pattern>
    </encoder>
  </appender>
  <root level="DEBUG">
    <appender-ref ref="file"/>
    <appender-ref ref="console"/>
  </root>
</configuration>

Unfortunately, I cannot reliably reproduce this error, so debugging it is a bit difficult. Could someone tell me either what I'm doing wrong, or what else might be the problem? If it's of any help, I redirect STDOUT and STDERR to /dev/null (I run on linux, btw).

+2  A: 

To debug the issue, use <configuration debug="true"> and don't redirect stdout. Logback will print messages there as it parses the config and when something goes wrong.

Aaron Digulla
I realize I can do this, but since I can't reproduce this behavior, it's very difficult to troubleshoot, even with all the information.But, I will try...
Markus Jevring
I ran with with debug and had a look at the output, and logback didn't complain. This was expected, as the configuration works fine most of the time.
Markus Jevring
Run it and wait for it to break. Then, you should see an error on stdout.
Aaron Digulla