Hello,

Solved ... I don't exactly understand why ... but solved.

I had to change my code in this way. Instead of:
System.setProperty("log4j.configurationFile", 
"/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml");
this.systemLog = LogManager.getLogger("LOGGER_SYSTEM");

Now is:
LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.setConfigLocation("/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml");

this.systemLog = context.getLogger("LOGGER_SYSTEM");


Thanks,

Joan.

-----Original Message-----
From: Joan ventusproxy <joan.balagu...@ventusproxy.com> 
Sent: Monday, October 17, 2022 1:47 PM
To: 'Log4J Users List' <log4j-user@logging.apache.org>
Subject: RE: Issue after moving to log4j 2.19

Hello,

Investigating a little more ...

If I set the variable 
-Dlog4j.configurationFile=/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml on 
the tomcat startup script, it works.

But setting this on my application, as we always did, it does not work any more:
System.setProperty("log4j.configurationFile", 
"/opt/ventusproxy/app/proxy/ROOT/WEB-INF/log4j.xml");

The point is this is a simplified example, building this path is much more 
complicated and it must be done at application level, not tomcat level.

By the way, our web.xml contains this:

  <context-param>
    <param-name>isLog4jContextSelectorNamed</param-name>
    <param-value>true</param-value>
  </context-param>

  <context-param>
    <param-name>log4jContextName</param-name>
    <param-value>ventusproxy</param-value>
  </context-param>

Thanks,

Joan.


-----Original Message-----
From: Joan ventusproxy <joan.balagu...@ventusproxy.com> 
Sent: Sunday, October 16, 2022 9:03 PM
To: 'Log4J Users List' <log4j-user@logging.apache.org>
Subject: RE: Issue after moving to log4j 2.19

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 <ralph.go...@dslextreme.com>
Sent: Sunday, October 16, 2022 2:44 AM
To: Log4J Users List <log4j-user@logging.apache.org>
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 
> <joan.balagu...@ventusproxy.com> 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/a59fb664774c44535c108
> 17900a80ed5/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/acd0a4edaf856ad34c44a
> 196caef7bdc/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.AsyncLogger
> ContextSelector
> 
> 
> 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 <piotr.karw...@gmail.com>
> Sent: Friday, October 14, 2022 5:23 PM
> To: Log4J Users List <log4j-user@logging.apache.org>
> 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#ContextSele
> ctor
> 
> `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




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

Reply via email to