We can externalize log4j2.properties file using system property -Dlog4j2.configurationFile=<file_path>, However, there are multiple web apps deployed on the same server, So, I want to explicitly set the file path for my web app only. One way is to use the below code. However, LoggerContext is a private API that can change in minor releases. Is there any easy way (without java code) to set web application-specific (or to say external log4j2.properties per web-app) external log4j2.properties file ?
// import org.apache.logging.log4j.core.LoggerContext;
LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
File file = new File("path/to/a/different/log4j2.xml");
// this will force a reconfiguration
context.setConfigLocation(file.toURI());