[logback-user] IllegalStateException caused by logback 1.1.2

Gena Makhomed gmm at csdoc.com
Wed May 28 18:33:21 CEST 2014


Hello, All!

to prevent "AsynAppender thread leak"
as described in http://jira.qos.ch/browse/LOGBACK-867
I use recommended in documentation
http://logback.qos.ch/manual/appenders.html#AsyncAppender
approach:

public class LogbackShutdownHook implements ServletContextListener {
     // ...
     @Override
     public void contextDestroyed(ServletContextEvent sce) {
         logger.info("******* stop logger *******");
         LoggerContext loggerContext = (LoggerContext) 
LoggerFactory.getILoggerFactory();
         loggerContext.stop();
     }
}

web.xml:

     <listener>
 
<listener-class>com.pb.ivrcgate.util.servlet.LogbackShutdownHook</listener-class>
     </listener>

but this causes IllegalStateException in tomcat log:

May 28, 2014 3:36:36 PM org.apache.catalina.loader.WebappClassLoader 
loadClass
INFO: Illegal access: this web application instance has been stopped 
already.  Could not load ch.qos.logback.core.status.WarnStatus.  The 
eventual following
java.lang.IllegalStateException
         at 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
         at 
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
         at 
ch.qos.logback.classic.LoggerContext.noAppenderDefinedWarning(LoggerContext.java:175)
         at ch.qos.logback.classic.Logger.callAppenders(Logger.java:267)
         at 
ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:442)
         at 
ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:396)
         at ch.qos.logback.classic.Logger.log(Logger.java:788)
         at 
org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
         at 
org.apache.http.impl.conn.PoolingHttpClientConnectionManager.shutdown(PoolingHttpClientConnectionManager.java:345)
         at 
org.apache.http.impl.conn.PoolingHttpClientConnectionManager.finalize(PoolingHttpClientConnectionManager.java:168)
         at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
         at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:101)
         at java.lang.ref.Finalizer.access$100(Finalizer.java:32)
         at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:190)

in my webapp org.apache.httpcomponents:httpclient:4.3.3 used.

sourse PoolingHttpClientConnectionManager.java line #345 is:

         this.log.debug("Connection manager is shutting down");

==============================================================

how to prevent IllegalStateException in tomcat log?

I am doing something wrong, or this is bug in logback code?

1) may be method shutdown() should be added to logback,
and after shutdown - all events and messages should be silently ignored?

2) or better add to logback new "fallback mode" - in this mode
all async appenders should be stopped and all buffers disabled,
all events written to logs and flushed immediately, without delays.

"fallback mode" can be used in contextDestroyed() methods
or in low memory conditions, before near OutOfMemoryError
to prevent any logging events lost in buffers and queues.

3) ................................... something else?

-- 
Best regards,
  Gena


More information about the Logback-user mailing list