Re: can we set log4j property 'Log4jContextSelector' per webapps war
Ralph Goers <[email protected]>
| Newsgroups | gmane.comp.jakarta.log4j.user |
|---|---|
| Message-ID | <[email protected]> |
Where are the Log4j jars located? Ralph > On Apr 6, 2022, at 6:34 AM, Pooja Pandey <[email protected]> wrote: > > 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