问题描述
我正在使用 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.
推荐答案
首先,您需要为每个环境准备一份不同的 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
这个 URL 有关于如何将它传递给 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!