log4j picking up wrong properties file

2019-02-19 04:08发布

There are 2 log4j.properties files in my classpath. I need both of them - One of them is required for a library that I am using and another is the one used by my code. When I run my jar file, it is able to read the properties used by the library, but it is not reading my own properties file. How can I make it read my log4j without having to use PropertytConfigurator in all my source files? Is there any way I can configure it so that it used both the properties files together?

3条回答
霸刀☆藐视天下
2楼-- · 2019-02-19 04:23

To answer your first question, you can point it to your own file by giving it a unique name and adding the following system property when you launch your application.

-Dlog4j.configuration=path_to_my_properties_file

I don't think it is possible to use 2 different files without doing anything programatically.

查看更多
Deceive 欺骗
3楼-- · 2019-02-19 04:31

Two log4j.properties files will surely create a mess (as you've experienced).

I'd suggest removing the library's version (why is it a requirement?), and combining both .properties files into one.

查看更多
对你真心纯属浪费
4楼-- · 2019-02-19 04:32

All logging goes into a single property file. Within that file you can differentiate between your own classes and the library's logging configuration.

查看更多
登录 后发表回答