Registering in an application in another Log4j environment

I am developing a logging framework using Log4j. I cannot figure out how to maintain separate log files for different environments, i.e. Development, testing, formulation and production.

+6
logging deployment configuration log4j
source share
2 answers

First, you will need a different copy of your log4j.xml for each environment.

Lets call it log4j-dev.xml, log4j-test.xml, log4j-stage.xml and log4j-prod.xml, each of which has its own settings, such as the name of the log file and log levels.

Then you transfer the corresponding file at server startup as a system property, as shown below -

-Dlog4j.configuration=log4j-dev.xml 

This URL has an example of how to pass this for Tomcat. The concept is the same for any server on which you deploy.

+12
source share

On Windows, I used "set CATALINA_OPTS=-Dlog4j.configurationFile=log4j2-dev.xml" instead of log4j.configuration

+1
source share

All Articles