Log4j 2
  1. Log4j 2
  2. LOG4J2-452

Log4j2 should not automatically start in Servlet 3.0

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta9
    • Fix Version/s: 2.0-rc1
    • Component/s: Filters
    • Labels:
      None

      Description

      When using async servlet (async-supported=true inweb.xml), log4j2 breaks the async chain because it does not support async. All element in the chain must support async in order to use async. Using Log4j2 in web context lead to be unable to use async.

      Be aware that async mecanism is more complicated than just intercept the chain before and after the handling of the request (thing that could be done in sync context). When using async mecanism web container threads can be used when the start method is invoked on AsyncContext and there are no way to intercept this systematically.

      So I m not sure that it's a good idea to automatically intercept request with a filter.

      1. patch_async.diff
        17 kB
        Anthony Communier
      2. log4-servlet-test.zip
        1.87 MB
        Anthony Communier
      3. 0002-Add-async-support-to-Log4jServletFilter.patch
        33 kB
        Matt Sicker
      4. 0001-Add-LOGGER_CONTEXT_ATTRIBUTE-to-LoggerContext.patch
        1 kB
        Matt Sicker

        Activity

        Anthony Communier created issue -
        Hide
        Anthony Communier added a comment -

        I try to make a patch in order to support async in the filter. But it's not enough.

        I have attched an exemple of test servlet

        Show
        Anthony Communier added a comment - I try to make a patch in order to support async in the filter. But it's not enough. I have attched an exemple of test servlet
        Anthony Communier made changes -
        Field Original Value New Value
        Attachment patch_async.diff [ 12613861 ]
        Attachment log4-servlet-test.zip [ 12613862 ]
        Hide
        Ralph Goers added a comment -

        I have concerns that automatically starting Log4j 2 just due to the presence of the jar is creating problems such as these.

        Show
        Ralph Goers added a comment - I have concerns that automatically starting Log4j 2 just due to the presence of the jar is creating problems such as these.
        Hide
        Matt Sicker added a comment -

        One of the issues to be addressed (which I'm currently thinking about) is setting the proper LoggerContext object for each and every thread that may be involved in asynchronous servlets and filters. In the synchronous servlets scenario, there's only the one thread per servlet, so this is easily taken care of with ContextAnchor. This approach probably won't work well in an asynchronous context.

        Show
        Matt Sicker added a comment - One of the issues to be addressed (which I'm currently thinking about) is setting the proper LoggerContext object for each and every thread that may be involved in asynchronous servlets and filters. In the synchronous servlets scenario, there's only the one thread per servlet, so this is easily taken care of with ContextAnchor. This approach probably won't work well in an asynchronous context.
        Hide
        Matt Sicker added a comment -

        Here's some work on the situation. There isn't much you can do in order to set the current thread's logger context when you add arbitrary multithreaded async servlet code. Thus, such situations should get the logger context from the servlet context.

        Show
        Matt Sicker added a comment - Here's some work on the situation. There isn't much you can do in order to set the current thread's logger context when you add arbitrary multithreaded async servlet code. Thus, such situations should get the logger context from the servlet context.
        Matt Sicker made changes -
        Nick Williams made changes -
        Assignee Nick Williams [ beamerblvd ]
        Nick Williams made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Nick Williams added a comment -

        Partially fixed with r1561956 in that the filter now supports async requests and the web support is exposed via a ServletContext attribute so that asynchronous threads can set and clear the LoggerContext. I still need to implement the context parameter that allows disabling auto-initialization.

        Show
        Nick Williams added a comment - Partially fixed with r1561956 in that the filter now supports async requests and the web support is exposed via a ServletContext attribute so that asynchronous threads can set and clear the LoggerContext . I still need to implement the context parameter that allows disabling auto-initialization.
        Hide
        Nick Williams added a comment -

        The rest of this has been fixed with r1561958, which adds a ServletContext parameter for disabling auto-initialization. A separate commit tomorrow will provide several updates to Log4j's web app documentation.

        Show
        Nick Williams added a comment - The rest of this has been fixed with r1561958, which adds a ServletContext parameter for disabling auto-initialization. A separate commit tomorrow will provide several updates to Log4j's web app documentation.
        Nick Williams made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 2.0-rc1 [ 12325011 ]
        Resolution Fixed [ 1 ]
        Hide
        Nick Williams added a comment -

        Documentation updated with r1562365.

        Show
        Nick Williams added a comment - Documentation updated with r1562365.

          People

          • Assignee:
            Nick Williams
            Reporter:
            Anthony Communier
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 466h
              466h
              Remaining:
              Remaining Estimate - 466h
              466h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development