'Logs not printing after migrating from log4j-1.2.17 to Log4j2 2.17.1

I am trying to migrate from log4j-1.2.17 to log4j-api-2.17.1 but after all the changes, the logs are not getting printed. I am using 'Option 2' as suggested by the https://logging.apache.org/log4j/2.x/manual/migration.html .

I have added lo4j-api-2.17.1.jar and log4j-core-2.17.1.jar in my libs folder and properly configured log4j2.xml in the src/resources/... folder.

There are no build errors nor any errors or warnings in my console when I run my Weblogic 12c server. It is a jdk 1.6 and struts 2 java web application.

The logs print fine when I use below VM args:

-Dlog4j2.configurationFile=%LOG_PATH% -Dlogpath=%LOGS%
set LOG_PATH=C:\bea\user_projects\domains\app_domain\conf\log4j2.xml
set LOGS=C:\bea\user_projects\domains\app_domain\logs

But this method is not acceptable for Prod env due to business requirements. Is there any alternative to perform the tasks of VM args through java code without using the VM args?



Solution 1:[1]

The alternative way is to use System properties. Then you programmatically add properties:

System.setProperty("log4j2.configurationFile", "/path/to/log4j2.xml");

You can add this code to the dispatcher listener. See how the dispatcher listener should be used.

Referencies:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1