简体   繁体   中英

How can I define an arbitrary file outside my web application to configure log4j2

My web application will be deployed to Weblogic application servers on Windows and Linux/Unix in different environments. The log file location, appenders and log levels will vary between the different deployments and we would like to be able to change the logging configuration during runtime (by exchanging the config file), so I cannot embed a log4j2.xml (or whatever other config file) into my deployment. And since I'm running on Application servers I cannot control, I've got no chance to add environment variables to point to another configuration Location.

Currently, my log4j2.xml resides in the classpath of my application and is being packaged into my war file. Is there any way to tell Log4J2 to use a configuration file eg relative to the application root (like Log4J's configureAndWatch(fileLocation) method)?

I found lots of examples of how to configure Log4J2, but everything I found about the config file location points to the applications class path.

I finally found a solution for my problem. I added a file named

log4j2.component.properties

to my project (in src/main/resources). This file contains a property pointing to the location of my log4j2 configuration file:

log4j.configurationFile=.//path//on//my//application//server//someLog4j2ConfigFile.xml

This causes log4j2 to read that file and configure itself from it's content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM