Log4j2 should not automatically start in Servlet 3.0

Details

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.

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.

Matt Sicker
added a comment - 18/Jan/14 04:29 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.

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
added a comment - 19/Jan/14 01:26 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.

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.

Nick Williams
added a comment - 28/Jan/14 07:15 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.

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
added a comment - 28/Jan/14 07:31 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.