You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2016/04/01 04:21:25 UTC
[jira] [Closed] (LOG4J2-1346) Exception from
Log4jServletContextListener prevents jetty-maven-plugin run-forked.
[ https://issues.apache.org/jira/browse/LOG4J2-1346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory closed LOG4J2-1346.
--------------------------------
Resolution: Fixed
Closing after title update.
> Exception from Log4jServletContextListener prevents jetty-maven-plugin run-forked.
> ----------------------------------------------------------------------------------
>
> Key: LOG4J2-1346
> URL: https://issues.apache.org/jira/browse/LOG4J2-1346
> Project: Log4j 2
> Issue Type: Bug
> Components: Web/Servlet
> Affects Versions: 2.5
> Reporter: Simon Xianyu
> Priority: Minor
> Fix For: 2.6
>
>
> I tried to integrate jacoco in my maven web project.
> However it always failed with the following logs:
> [WARNING] FAILED o.e.j.m.p.JettyWebAppContext@1d831c2{/,file:/D:/works/paypos2/jacoco-spring/src/main/webapp/,UNAVAILABLE}{file:/D:/works/paypos2/jacoco-spring/src/main/webapp/}: java.lang.IllegalStateException: C
> ontext destroyed before it was initialized.
> java.lang.IllegalStateException: Context destroyed before it was initialized.
> at org.apache.logging.log4j.web.Log4jServletContextListener.contextDestroyed(Log4jServletContextListener.java:55)
> I read the code and found Exception throw in org.apache.logging.log4j.web.Log4jServletContextListener.contextDestroyed:
> if (this.servletContext == null || this.initializer == null) {
> throw new IllegalStateException("Context destroyed before it was initialized.");
> }
> This runtime exception fails jetty-maven-plugin web application configuration validation.
> So I have to write my own Listener to work around: (Log4jWebLifeCycle is not public, so I have to use public interface to operate.)
> public void contextDestroyed(final ServletContextEvent event) {
> // if (this.servletContext == null || this.initializer == null) {
> // throw new IllegalStateException("Context destroyed before it was initialized.");
> // }
> // LOGGER.debug("Log4jServletContextListener ensuring that Log4j shuts down properly.");
> if (this.initializer != null) {
> if (this.initializer instanceof Log4jWebSupport) {
> ((Log4jWebSupport)this.initializer).clearLoggerContext(); // the application is finished shutting down now
> }
> this.initializer.stop();
> }
> }
> I think using a warning log is better than throw an exception in contextDestroyed, because this is shutting down stage.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org