简体   繁体   English

如何在一处为整个项目初始化log4j系统?

[英]How to initialize log4j system for entire project at one place?

In my project, I've to use log4j but in every class, I've mention following - 在我的项目中,我必须使用log4j但在每个类中,我都提到以下内容-

final static Logger logger = Logger.getLogger(<className>.class);
PropertyConfigurator.configure(<pathOfLog4jPropertiesFile>);

Line #1 must be in every class as it talks about the class itself but line #2 is duplicated in every class as it is same across all classes. 第1行必须在每个类中,因为它谈论该类本身,但是第2行在每个类中都重复,因为它在所有类中都是相同的。

Is there any way we can have that configuring properties file at once place and need to write it in every class? 有什么办法可以让配置属性文件一次放置并需要在每个类中编写它?

Please do suggest if there is any other better way with which I can use log4j. 请建议是否还有其他更好的方法可以使用log4j。

you can pass an arg at startup -Dlog4j.configurationFile= 您可以在启动时传递arg -Dlog4j.configurationFile =

Ensure that all dependencies are in place for your libraries which might be using slf4j or other such logging apis. 确保可能正在使用slf4j或其他此类日志记录API的库的所有依赖项均已就绪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM