RE: Issue after moving to log4j 2.19

2022-10-16 Thread Joan ventusproxy
Is not this? (second gist):

DEBUG StatusLogger Watching configuration 
'/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml' for lastModified Sat Oct 15 
21:55:38 UTC 2022 (1665870938000)
DEBUG StatusLogger Apache Log4j Core 2.19.0 initializing configuration 
XmlConfiguration[location=/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml]

Joan.

-Original Message-
From: Ralph Goers  
Sent: Sunday, October 16, 2022 2:44 AM
To: Log4J Users List 
Subject: Re: Issue after moving to log4j 2.19

In both of those log files Log4j is not seeing any value as being set of 
log4j.configurationFile. It is ending up using the default configuration.

Ralph

> On Oct 15, 2022, at 3:45 PM, Joan ventusproxy 
>  wrote:
> 
> Hi Piotr,
> 
> Thanks for your quick response.
> 
> Below two gists with the traces for both cases:
> 
> 1. Using "this.systemLog = LogManager.getLogger("LOGGER_SYSTEM");":
> https://gist.githubusercontent.com/joanbalaguero/a59fb664774c44535c10817900a80ed5/raw/8bb6b6a963a607f0d99105248ce32a28ad39590a/gistfile1.txt
> 
> In this case logs are not created.
> 
> 
> 2. Using "this.systemLog = 
> LogManager.getContext().getLogger("LOGGER_SYSTEM");":
> https://gist.githubusercontent.com/joanbalaguero/acd0a4edaf856ad34c44a196caef7bdc/raw/474febc0397b97a9b941dbd86b830149ac94ad07/gistfile1.txt
> 
> In this case logs are created and content is logged into them correctly, but 
> the hazelcast log (from "com.hazelcast") is not sent to the SYSTEM_LOG. 
> 
> 
> The " log4j.configurationFile " variable is set in this way:
> System.setProperty("log4j.configurationFile", 
> "/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml");
> 
> And tomcat starts with:
> -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
> 
> 
> The point is that for years we have been running this without issues using 
> point 1, without getting the context from the LogManager.
> 
> One more clue. As I said, this is not working fine on our new installation 
> with Centos9 Stream, Apache Tomcat 8.5.83 and Zing JVM 11. Exactly the same 
> code running locally on a windows 10 with Apache Tomcat 8.5.39 and Oracle jdk 
> 11 works perfectly, logs are created and the hazelcast logging is sent to the 
> SYSTEM_LOG.
> 
> 
> Thanks,
> 
> Joan.
> 
> -Original Message-
> From: Piotr P. Karwasz  
> Sent: Friday, October 14, 2022 5:23 PM
> To: Log4J Users List 
> Subject: Re: Issue after moving to log4j 2.19
> 
> Hi Joan,
> 
>> After making a lot of tests trying to get this working again, we had to 
>> change the line below:
>> 
>> this.systemLog = LogManager.getLogger("LOGGER_SYSTEM");
>> 
>> 
>> 
>> By this:
>> 
>> this.systemLog = LogManager.getContext().getLogger("LOGGER_SYSTEM");
> 
> This looks like a `LoggerContextSelector` problem:
> https://logging.apache.org/log4j/2.x/manual/extending.html#ContextSelector
> 
> `LogManager.getContext()` should not be used, because it gives you the wrong 
> logger context most of the time.
> The automatic configuration uses `LogManager.getContext(false)` to retrieve 
> the right logger context.
> 
> Can you run your application with `-Dlog4j2.debug=true` and share the output?
> 
> Piotr
> 
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 
> 
> 
> 
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 


-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org




-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: Issue after moving to log4j 2.19

2022-10-16 Thread Piotr P. Karwasz
Hi Joan,

On Sun, 16 Oct 2022 at 00:45, Joan ventusproxy
 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 `` 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

-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org