Deprecation of Log4j Supplier in 2.x...why? 

2024-03-14 Thread Jeffrey.Thomas
Hello Log4j Team,

One of the great new features of Log4j2 is the lambda lazy logging.

Since we migrated to Log4j2 we have liberally been trying to take advantage of 
this where we can.

In the last few releases though, in preparation for Log4j 3.x the Log4j 
Supplier has been deprecated without replacement.

I get why you did this, but ... "why?" did you do this? 

Our builds are now ***full*** of deprecation warnings.  The IDE shows 
deprecation highlighting everywhere. Also, CI builds i.e. with Sonar evaluate 
use of deprecated API as Code Smells and Quality Gates fail.  When SQ quality 
gates fail our downstream jobs don't trigger.

I read Hibernate did something similar to indicate "intent" without 
replacement, but they ultimately ended up reverting that change.

Cheers, Jeff


Re: log4j initialization does not seem to happen when Tomcat service is started

2024-03-14 Thread Piers Uso Walter
Hi Piotr,

Thanks for your explanation.

Indeed, once I hard code the path to the log4j configuration file into web.xml, 
logging works in both cases (app undeployment/deployment as well as Tomcat 
shutdown/restart).

However, what I was trying to achieve by using a servlet context listener was 
to be able to set the location of the log4j configuration file at run time.
I’m trying to make the app compatible with different app servers where 
configuration files are typically placed in different locations.
So I’m figuring out at run time which app server the app is running in, and 
based on that I know where to expect the log4j configuration file.

Is there any way to do this? Or am I stuck with using a fixed path via web.xml?

Thanks,
Piers



> Am 13.03.2024 um 23:35 schrieb Piotr P. Karwasz :
> 
> Hi Piers,
> 
> On Wed, 13 Mar 2024 at 22:29, Piers Uso Walter  wrote:
>> 2024-03-13T19:49:02.609143Z Catalina-utility-1 INFO 
>> Log4jServletContextListener triggered a Log4j context initialization.
>> 
>> Case 2:
>> However, if I stop and restart the Tomcat service (with the war file having 
>> been previously deployed), the app no longer logs anything and I don’t see a 
>> catalina log line about Log4j context initialization:
> 
> The message in the first line is not logged through Log4j Core, but
> the status logger (an internal logging system of the Log4 API). You
> can set the level of the status logger using the
> `log4j2.StatusLogger.level` property. By default it only shows `ERROR`
> messages, but it changes level based on the `status` property
> 
>> I configured a servlet context listener in order to be able to set the 
>> system property log4j.configurationFile upon application start.
>> This allows me to place the log4j configuration file outside of the war file.
> 
> A servlet context listener is not the right tool for this, since it is
> executed **after** Log4j's `ServletContainerInitializer`.
> You should rather specify the property as a servlet context init
> parameter. See the current documentation:
> 
> https://logging.apache.org/log4j/2.x/manual/webapp.html#configuration
> 
> or a preview of the documentation of the next major version:
> 
> https://logging.staged.apache.org/log4j/jakarta/latest/#log4j-jakarta-web-configuration
> 
>> This is my web.xml:
>> 
>> http://www.w3.org/2001/XMLSchema-instance; 
>> xmlns="http://xmlns.jcp.org/xml/ns/javaee; 
>> xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
>> http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd; id="WebApp_ID" 
>> version="3.1">
>> 
>>
>>
>>
>> de.ilink.cloud.ucc.gw.LdapGwServletContextListener
>>
>> 
>> 
> 
> You should add:
> 
>
>log4jConfiguration
>path_to_your_config_file_or_resource
>
> 
> Also if your context listener uses logging, you might want to register
> a `Log4jServletContextListener` manually, so it shuts down **after**
> your listener:
> 
>
>
> org.apache.logging.log4j.web.Log4jServletContextListener
>
>
>
>
> de.ilink.cloud.ucc.gw.LdapGwServletContextListener
>
> 
> 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