Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-873

Memory leak in web container caused by incorrect log4j initialization when omitting display-name element in web.xml

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.2
    • 2.5
    • Web/Servlet
    • None

    Description

      The initializeNonJndi method in Log4jWebInitializerImpl uses servletContext.getServletContextName() to get a context name (if the name hasn't been defined using log4jContextName). getServletContextName() returns the name as specified in the <display-name> element in web.xml, but that is optional.

      If neither <display-name> nor log4jContextName is defined, this results in the servletContext not being set, so the WebLookup doesn't work. The following error is displayed on the console:

      No Log4j context configuration provided. This is very unusual.

      It should use some sort of default. Probably the name of the war file or context file, if there's a generic way of getting that.


      Follow-up: as noted below, it is more than just WebLookup that fails if this happens. Log4j is initialized incorrectly: logging will work, but when the web application is stopped the logging context is not stopped, causing Tomcat to complain about Threads not being stopped and ThreadLocals not being cleaned up.

      Attachments

        Activity

          People

            rpopma Remko Popma
            MartinDickins Martin Dickins
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: