Hari Menon
Hari Menon

Reputation: 35485

log4j picking up wrong properties file

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?

Upvotes: 3

Views: 2424

Answers (3)

KevinS
KevinS

Reputation: 7882

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.

Upvotes: 4

darioo
darioo

Reputation: 47213

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.

Upvotes: 3

cherouvim
cherouvim

Reputation: 31928

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

Upvotes: 1

Related Questions