Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j.properties in multiple maven modules?

Tags:

java

maven

log4j

What happens, when I have a maven application consisting of multiple modules and each of them contains a log4j.properties file, do they get merged or overwritten by a certain one (if yes, which one)?

Update: Following your advice I have now excluded the additional properties like this in my poms:

<dependency>
[...]
<excludes><exclude>**/log4j.properties</exclude></excludes>
</dependency>

P.S.: However, the "excludes" tag is not recognized by Maven and "exclusions" only works for dependencies, not resources.

Update

Just found out in log4j in a multi-module Maven project that I can just put the log4j.properties in src/test/resources so that they aren't included anyways in the executable module!.

like image 291
Konrad Höffner Avatar asked Feb 20 '14 15:02

Konrad Höffner


People also ask

Where should Log4j properties be placed?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

Does Maven use Log4j?

java - A Maven plugin uses a library which logs with log4j - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

What is the difference between Log4j and Log4j2?

Community support: Log4j 1. x is not actively maintained, whereas Log4j 2 has an active community where questions are answered, features are added and bugs are fixed. Automatically reload its configuration upon modification without losing log events while reconfiguring.


2 Answers

They never get merged. Generally, the log4j.properties files get overwritten and you can not exactly tell which one.

It depends on the sequence of loading the Jar files by container.

So It is recommended to have one log4j.properties with multiple appenders each for other sub-modules in the core module of your application.

But it would create problem while testing/working with sub-modules independently as it will stop logging when tested separately. In our case, the source control version of pom always used to exclude resource (which will exclude the properties file while building the jar). However in developer local, developers used to comment that exclusion in POM and can work independently.

like image 69
sakura Avatar answered Oct 16 '22 04:10

sakura


For example if you have 2 projects one for data and another for presentation. And both have the log4j.properties. And when you deploy the war file which also contains the data file inside it. Only the presentation project has the effect. And the log4.properties in the data project would be ignored. They will never get merged or over written by itself.

like image 28
Jay Avatar answered Oct 16 '22 02:10

Jay