自定义位置中的Log4j属性 [英] Log4j Properties in a Custom Place

查看:281
本文介绍了自定义位置中的Log4j属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Commons Logging和SLF4J与log4j,但我也想在conf / log4.properties这样的自定义位置使用log4j.properties。这是问题所在:



如果我使用

  PropertyConfigurator.configure ( CONF / log4j.properties); 

然后我的应用程序与log4j绑定,并且无法使用ACL和SLF4J。



在没有应用程序了解日志记录实现的情况下配置它的最佳方法是什么?

解决方案

我认为最简单的方法是使用 log4j.configuration 系统属性指定文件的位置。采用 Log4J手册中的示例:



'pre> 的java -Dlog4j.configuration = CONF / log4j.properties -classpath ...

我相信Log4J会在类路径的任何地方找到一个名为log4j.properties的文件,但可能会产生幻觉。值得一试。


I'm using Apache Commons Logging and SLF4J with log4j, but I also want to use the log4j.properties in a custom place like conf/log4.properties. Here is the problem:

If i use

  PropertyConfigurator.configure("conf/log4j.properties");

then my app is tied to log4j and defeats the purpose of having ACL and SLF4J.

What is the best way to configure it without the app ever knowing what the logging implementation is?

解决方案

I think the easiest thing to do is specify the location of the file using the log4j.configuration system property. Adopting the example in the Log4J manual:

java -Dlog4j.configuration=conf/log4j.properties -classpath ...

I believe that Log4J will find a file named "log4j.properties" anywhere on the classpath, but may be hallucinating. Worth trying, however.

这篇关于自定义位置中的Log4j属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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