Search code examples
javalog4j2tomcat8

How pass log4j2.xml to Tomcat application


I have application which is running at Tomcat 8 server. Application use log4j2 for internal logging. I want to have one application.war and two different log config files like: log4j2_dev.xml and log4j2_prod.xml depending from environment.

In production environment I want deploy application.war and use log4j2_prod.xml And in development environment I want deploy application.war and use log4j2_dev.xml

So, how could I specify which file to use during application.war deploying?

PS. I don't want build two different wars like application_prod.war and application_dev.war with different configs inside.


Solution

  • In the $CATALINA_BASE/bin/setenv.sh file I've added the line:

    export LOG4J_CONFIGURATION_FILE=/dev/log4j2_dev.xml