Logging for application in different environment Log4j

后端 未结 2 1058
南方客
南方客 2020-12-10 07:15

I am developing a logging framework using Log4j. I am not able to figure out how to maintain separate log files for different environment, i.e., development, testing, stagin

相关标签:
2条回答
  • 2020-12-10 07:26

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

    0 讨论(0)
  • 2020-12-10 07:46

    Firstly you'll 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 having their own settings like log file name and log levels.

    You then pass in the corresponding file at the the server startup as a system property like below -

    -Dlog4j.configuration=log4j-dev.xml
    

    This URL has the example on how to pass this for Tomcat. The concept is the same for whichever server you are deploying on.

    0 讨论(0)
提交回复
热议问题