[logback-user] OverlappingFileLockException when using common log among 2 tomcat contexts in same JVM.

Christopher Holt chris.holt at hcs.us.com
Wed Sep 18 17:30:36 CEST 2013


Hello,

I have logback configured so that code bundled in 2 different war files
under tomcat will write to the same log file which rolls daily.  It's also
marked as prudent.  I believe my configuration follows the guidelines from (
http://logback.qos.ch/manual/appenders.html#prudentWithRolling).

<configuration>
  <appender name="A1"
class="ch.qos.logback.core.rolling.RollingFileAppender">
    <prudent>true</prudent>
    <encoder>
            <pattern>%d{dd-MM HH:mm:ss} [%t] %c %5p %m%n</pattern>
    </encoder>
    <rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<FileNamePattern>${catalina.base}/logs/myapp.%d{yyyy-MM-dd}.log</FileNamePattern>
        <MaxHistory>30</MaxHistory>
    </rollingPolicy>
  </appender>

  <root level="INFO">
    <appender-ref ref="A1"/>
  </root>
</configuration>

My problem is that I get lots
of java.nio.channels.OverlappingFileLockException.
...
java.nio.channels.FileChannel.lock(FileChannel.java:860)
ch.qos.logback.core.FileAppender.safeWrite(FileAppender.java:187)
ch.qos.logback.core.FileAppender.writeOut(FileAppender.java:204)
ch.qos.logback.core.OutputStreamAppender.subAppend(OutputStreamAppender.java:212)
...

After reading the docs for OverlappingFileLockException, my hunch is that
the 2 different loggers, loaded by different class loaders within the same
JVM are both trying to lock the file, unbeknownst to each other.  This
violates the rules for FileChannel.lock, which seem to ignore the issue of
locks among multiple class loaders within 1 JVM.

Has anyone run into this issue before?  Is there a simple workaround that
I'm not thinking of?

Thanks,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130918/6bea583f/attachment.html>


More information about the Logback-user mailing list