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

Xavier Dury kalgon at hotmail.com
Mon Sep 23 12:52:09 CEST 2013


Hi,

I am also trying such tomcat configuration and this is the one I'm using now:


1. put logback and slf4j jars in $CATALINA_BASE/lib (not in WAR)

2. in $CATALINA_BASE/bin/setenv.sh
   export CATALINA_OPTS=\
      -Dlogback.configurationFile=$CATALINA_BASE/conf/logback.xml \
      -Dlogback.ContextSelector=JNDI

3. place your logback.xml in $CATALINA_BASE/conf
   I'm using SiftingAppender with JNDIBasedContextDiscriminator and %contextName in my pattern

4. create $CATALINA_BASE/conf/{tomcatEngineName}/{tomcatHostName}/web.xml.default
   with LoggerContextFilter and ContextDetachingSCL

5. in $CATALINA_BASE/conf/{TEN}/{THN}/{yourAppContext}.xml,
   add an env-ref <Environment name="/logback/context-name" type="java.lang.String" value="yourContextIdentifier" /> so you can use %contextName in your pattern


If you want to use logback-access too:


6. put your logback-access.xml file in $CATALINA_BASE/conf

7. create $CATALINA_BASE/conf/{TEN}/{THN}/context.xml.default and add
   <Valve className="ch.qos.logback.access.tomcat.LogbackValve" quiet="true" filename="${catalina.base}/conf/logback-access.xml" />

Only problem I got so far is that I can't use a SiftingAppender that will fetch the contextName from JNDi with logback-access. There is no equivalent to classic's JNDIBasedContextDiscriminator in access.

What's great is that my webapp has zero dependency to logback, it's just using slf4j at compile time (maked as provided in maven) and the rest is provided by the container at runtime.

Xavier

________________________________
> Date: Thu, 19 Sep 2013 11:10:18 -0400 
> From: james.scollard at weather.com 
> To: logback-user at qos.ch 
> Subject: Re: [logback-user] OverlappingFileLockException when using 
> common log among 2 tomcat contexts in same JVM. 
> 
> We are currently deploying the following logback jar files to all 
> tomcat instances: 
> 
> logback-access-1.0.13.jar 
> logback-classic-1.0.13 
> logback-core-1.0.13 
> 
> These libraries are currently deployed by Puppet to all Tomcat 
> instances via the twc_tomcat module and are placed in the 
> $CATALINA_HOME/lib directory to be accessible by all contexts. 
> Additionally we are deploying puppet template (full variable and 
> settings control) files for tomcat7.conf, server.xml, 
> logback-access.xml, logback.xml, log4j.properties, and 
> inbound/outbound-api-runtime.properties files to the 
> $CATALINA_HOME/conf (alias) /etc/tomcat7 config directories. 
> 
> If you keep a localhost version of the required configuration files in 
> your WAR and then reference the external files (-Dconfig references) as 
> preferred you will avoid any compiler errors while still allowing 
> automated control of these properties. We are also leveraging 
> logrotate to ensure that files are maintained for a reasonable period 
> but do not grow large enough to kill the node, and will be leveraging 
> rsyslogd to eventually push copies of log messages to Logstash on a 
> remote cluster. 
> 
> Hopefully this helps. 
> 
> On 9/19/13 10:57 AM, Christopher Holt wrote: 
> David, 
> 
> If I move all of the logback, log4j, etc jars to tomcat/lib, then it 
> fails to find the logback.xml in my conf/Catalina/localhost directory. 
> 
> Jars involved: 
> 
> jcl-over-slf4j-1.7.5.jar 
> jul-to-slf4j-1.7.5.jar 
> log4j-over-slf4j-1.7.5.jar 
> logback-access-1.0.13.jar 
> logback-classic-1.0.13.jar 
> logback-core-1.0.13.jar 
> slf4j-api-1.7.5.jar 
> 
> I really want to keep the logback.xml config out of the war files. 
> Different deployments will have different logging strategies. I also 
> need separate logback.xml's per tomcat instance. Where can I keep my 
> config so that it can be seen when the logback jars are not in the 
> wars? 
> 
> Thanks, 
> -Chris 
> 
> 
> 
> On Thu, Sep 19, 2013 at 3:53 AM, David Roussel 
> <nabble at diroussel.xsmail.com<mailto:nabble at diroussel.xsmail.com>> 
> wrote: 
> Where is logback on the class path? If it is in the wars, try taking it 
> out and putting it in the tomcat class path. 
> 
> David 
> 
> On 18 Sep 2013, at 16:30, Christopher Holt 
> <chris.holt at hcs.us.com<mailto:chris.holt at hcs.us.com>> wrote: 
> 
> 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 
> 
> _______________________________________________ 
> Logback-user mailing list 
> Logback-user at qos.ch<mailto:Logback-user at qos.ch> 
> http://mailman.qos.ch/mailman/listinfo/logback-user 
> 
> _______________________________________________ 
> Logback-user mailing list 
> Logback-user at qos.ch<mailto:Logback-user at qos.ch> 
> http://mailman.qos.ch/mailman/listinfo/logback-user 
> 
> 
> 
> 
> _______________________________________________ 
> Logback-user mailing list 
> Logback-user at qos.ch<mailto:Logback-user at qos.ch> 
> http://mailman.qos.ch/mailman/listinfo/logback-user 
> 
> 
> -- 
> James E. Scollard III 
> 
> Senior Cloud Systems Architect 
> c: 615.730.4387 
> www.weather.com<http://www.weather.com> 
> 
> View my profile on LinkedIn 
> 
> 
> _______________________________________________ Logback-user mailing 
> list Logback-user at qos.ch 
> http://mailman.qos.ch/mailman/listinfo/logback-user 		 	   		  


More information about the Logback-user mailing list