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.
JoseK
source share