Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 not loading log4j2.xml

Tags:

log4j2

I have a problem concerning log4j2 which does not load the log4j2.xml configuration file in a project.

The project is bundled into an uber jar file. When running the application using java -jar jarfile.jar the application starts but log4j prints the following error to the console:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

I checked the jar and it definitely contains a log4j2.xml file in the root location.

Because I could not figure out why this does not work I debugged to log4j2 bootstrap code. I found out that log4j never tries to read the log4j2.xml. This should happen in org.apache.logging.log4j.core.config.ConfigurationFactory.Factory#getConfiguration.

Unfortunately the list of factories used in this method is empty thus the method always returns null.

Any ideas on this?


If you want to check this clone https://github.com/cryptomator/cryptomator, cd to the main directory in the cloned repo and run mvn clean install -DskipTests -P uber-jar afterwards you will find the jar file in question under main/uber-jar/target.

like image 531
Markus Kreusch Avatar asked Jun 16 '26 22:06

Markus Kreusch


1 Answers

I suspect this is the same issue as Log4j2 configuration not found when running standalone application builded by shade plugin since it sounds like you are building an uber jar.

like image 191
rgoers Avatar answered Jun 19 '26 19:06

rgoers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!