在不同环境中记录应用程序Log4j [英] Logging for application in different environment Log4j
问题描述
我正在使用Log4j开发日志框架。我不能找出如何为不同的环境,即开发,测试,分期和生产维护单独的日志文件。
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.
推荐答案
p>首先,您需要为每个环境提供一个不同的log4j.xml副本。
Firstly you'll need a different copy of your log4j.xml for each environment.
将其命名为log4j-dev.xml,log4j-test.xml,log4j-stage.xml和log4j-prod.xml,每个都有自己的设置,如日志文件名和日志级别。
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
此网址提供了如何将此传递给Tomcat的示例。对于您要部署的任何服务器,此概念都是相同的。
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屋!