For other 2 wars I get following harmless error when I keep 
'log4j2.component.properties' file on log4j jars class path, to fix class cast 
exception which I was getting earlier during deployment of my war file.

ERROR StatusLogger Unable to create custom ContextSelector. Falling back to 
default.

"java.lang.ClassCastException: Cannot cast 
logger.log4j2.CustomLog4j2ContextSelector to 
org.apache.logging.log4j.core.selector.ContextSelector".

-----Original Message-----
From: Pooja Pandey <pooja.pan...@asg.com.INVALID> 
Sent: Wednesday, April 6, 2022 7:04 PM
To: Log4J Users List <log4j-user@logging.apache.org>
Subject: can we set log4j property 'Log4jContextSelector' per webapps war

*** External email: Verify sender before opening attachments or links ***


Hi,

In my application, I have 2 processes running and there are 3 webapps war files 
which get deployed in tomcat version 9.0.60. Out of these 3 war files, one war 
file is internal to my application while other 2 are coming as final artifacts 
from artifiactory.

My war uses a custom logger and custom ContextSelector, however other 2 wars 
from artifactory uses standard logger and standard ContextSelector.

I have defined below system property as a static block in custom logger, 
however for some unknown reason when my war gets deployed this log4j jars don't 
find this property and leads to ClassCastException 
"java.lang.ClassCastException: 
org.apache.logging.log4j.core.selector.ContextSelector cannot be cast to 
logger.log4j2.CustomLog4j2ContextSelector". To fix this I have placed 
'log4j2.component.properties' file on log4j jars class path, but with this fix, 
following harmless error get logged for other 2 wars 
"java.lang.ClassCastException: Cannot cast 
logger.log4j2.CustomLog4j2ContextSelector to 
org.apache.logging.log4j.core.selector.ContextSelector".

I am looking for help to come up with a solution where, when my war gets 
deployed then custom logger context "logger.log4j2.CustomLog4j2ContextSelector" 
should be used while when other 2 wars get deployed then  
"org.apache.logging.log4j.core.selector.ContextSelector" should be used. Please 
let me know if you have any idea on this.

static {
    System.setProperty("Log4jContextSelector", 
"logger.log4j2.CustomLog4j2ContextSelector");
}


Content of file 'log4j2.component.properties' -> 
Log4jContextSelector=logger.log4j2.CustomLog4j2ContextSelector

---------------------------------------------------------------------
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