Issue
I'm setting up a new project with Spring MVC and I can't configure Log4j2, I'm getting the same error as many asked for help.
ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration...
Tools and libs:
pom.xml
...
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-jcl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.11.2</version>
</dependency>
...
Configuration files src location
/src/com/mypackage/myproject/resorces/
where I tried to put a log4j2-test.xml file and/or a log4j2.properties, none of them worked
Browsing Tomcat deployment dir:
.../org.eclipse.wst.server.core/tmp0/wtpwebapps/MonitorManagement/WEB-INF/classes/com/mypackage/myproject/resources
I can find both the resources.
How log4j2 is unable to locate them even if resources are actually deployed?
EDIT: It works putting resources directly under src folder, could this be a good way?
Thanks in advance
Solution
Log4j looks in the root folder in the classpath.
In your IDE you can put the log4j2.xml
file under /src
and (probably) under /resources
.
Answered By - Remko Popma
Answer Checked By - Gilberto Lyons (JavaFixing Admin)