在不同的环境中记录Log4j [英] Logging for application in different environment Log4j

查看:176
本文介绍了在不同的环境中记录Log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆