在不同的环境中记录Log4j [英] Logging for application in different environment Log4j
问题描述
p>首先,您需要为每个环境使用不同的log4j.xml副本。
让我们称之为log4j-dev.xml,log4j-test.xml,log4j-stage.xml和log4j-prod.xml,每个都有自己的设置,如日志文件名和日志级别。
然后,您可以在服务器启动时传入相应的文件作为系统属性,如下所示 -
-Dlog4j.configuration = log4j-dev.xml
此URL 有关如何传递给Tomcat的示例。这个概念与您部署的任何服务器相同。
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, staging and production.
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.
这篇关于在不同的环境中记录Log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!