Re: Issue after moving to log4j 2.19
"Piotr P. Karwasz" <[email protected]> Sun, 16 Oct 2022 10:06:31 +0200
| Newsgroups | gmane.comp.jakarta.log4j.user |
|---|---|
| Message-ID | <CAFmygFbzdiZxfyQRCuuM-bjs0YYqmg09e0tDi76GweLE_P5riA@mail.gmail.com> |
Hi Joan, On Sun, 16 Oct 2022 at 00:45, Joan ventusproxy <[email protected]> wrote: > The " log4j.configurationFile " variable is set in this way: > System.setProperty("log4j.configurationFile", "/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml"); For some unknown reason this is executed too late (after Log4j2 configuration). In the second file you posted you can see that Log4j2 is initialized twice: the first time the logger context associated with your web app's classloader picks up the default configuration, because no `log4j2.configurationFile` setting is visible. Then `log4j-web` configures what seems to be a second logger context with your configuration (but `log4j-web` uses the `ServletContext` init params to retrieve the configuration). To find which component calls Log4j2 before `log4j-web` you can use `-Dlog4j2.loggerContextStacktraceOnStart=true`. The web fragment `log4j` contained in `log4j-web` requests to be executed before all others, but you can change it with `<absolute-ordering>` in your `web.xml`. > And tomcat starts with: > -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector This setting basically breaks `log4j-web` ("WARN StatusLogger Potential problem: Selector is not an instance of NamedContextSelector."). Look into your web application descriptor and remove the `isLog4jContextSelectorNamed` parameter. You can also use the `BasicAsyncLoggerContextSelector` which always selects a thread bound logger context (`log4j-web` manages the thread binding). Piotr