Log4j2 is working nicely with Spring Boot through the log4j2.xml
configuration file in the root classpath, exactly as the documentation states.
When trying to move this file to a different location though, I'm not able to pass the new location to Spring at startup. From the documentation:
The various logging systems can be activated by including the appropriate libraries on the classpath, and further customized by providing a suitable configuration file in the root of the classpath, or in a location specified by the Spring Environment property
logging.config
.
I tried setting the new location with a Java system property
java -jar -Dlogging.config="classpath:/config/log4j2.xml" target/app.jar
or using an external application.properties
containing the relevant property
logging.config=classpath:/config/log4j2.xml
But I am regularly greeted by the following error message.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
/config
is in the classpath? if you are using maven based project, put the xml file undersrc/main/resources
– Tremblyconfig
folder (package) is in the classpath, and it already containsapplication.yml
, that is correctly picked up and succesfully used in the application. – Threlkeldsrc/main/resources
and try so that we can narrow down the issue? – Tremblysrc/main/java
), it works without problems. I'm not getting what we should check by putting the XML in thesrc/main/resources
folder. What I want to be able to do is to put the log4j2.xml file wherever I want. – Threlkeldsrc/main/java
, it means there is no problem with the configuration. If you want it to work irrespective of the location of thelog4j2.xml
, you have to make sure that the folder is in classpath. If you are using eclipse,right click on the project -> Build Path -> Configure Build Path
to set the classpath. – Tremblymvn spring-boot:run -Dlogging.config="/path/to/file/test.xml"
(or similarly when usingjava -jar
). Still, I've not been able to include a file already in the classpath at build time. I'm not sure that's actually possible. – Threlkeld