AugSB
AugSB

Reputation: 269

Ignore log4j2.properties from dependency jar

I have a Maven project, running correctly. I am using a log4j2.xml file to configure the logging. Until today everything was working fine. But now, I have included a dependency of a third-party jar that has its own log4j2.properties file. Unfortunately, this is overwritting my own configuration.

Is there any way I can ignore, exclude... that property file?

Upvotes: 3

Views: 2198

Answers (2)

rgoers
rgoers

Reputation: 9151

Actually, the other answers are incorrect as they are advising you to use the system property log4j 1.x uses, not what Log4j 2 uses.

For Log4j 2 you want to use -Dlog4j2.configurationFile=/path/to/log4j2.xml. If you only specify -Dlog4j2.configurationFile=log4j2.xml then Log4j will look for that file on the class path. Obviously the name can be anything you want. Log4j also supports putting the system properties in a file named log4j2.component.properties so if you do not want to specify them on the command line you can include them in a Java Properties file with that name in your application.

No matter what you do you should open a bug with the third party as putting a logging configuration file in a library jar is a bad practice.

Upvotes: 4

Ali Ben Zarrouk
Ali Ben Zarrouk

Reputation: 2018

You can add an option to specify your own log4j properties file with

-Dlog4j.configuration=path/to/my.properties and thats better than excluding everytime a new library tries to override your properties file.

Upvotes: -1

Related Questions