Reputation: 3145
I'm trying to set up SLF4J to work with Log4J2. But I keep getting this error:
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Here are my POM Dependencies:
<properties>
<log4j.version>2.1</log4j.version>
</properties>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
I'm using a simple config for testing:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
And my log4j2.xml file is located in src/main/resources.
I'm not sure what else to check. I've also tried moving the xml file to the /src directory, but it didn't help. What am I missing?
Upvotes: 4
Views: 6888
Reputation: 1124
You don't specify the server you are using to deploy and I was running into this same issue when trying to deploy my web application on Wildfly 8.1 and have my log4j2.xml in the src/main/resources folder.
It's pointed out in this thread that it's not a log4j2 bug but a bug in the JBoss/Wildfly code.
Quoting Hassan Kalaldeh on the thread:
I found what is the problem, if you extract log4j-web-2.1.jar and open servlet container Initializer service in file : log4j-web-2.1\META-INF\services\javax.servlet.ServletContainerInitializer you will find this: javax.servlet.ServletContainerInitializer
# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache license, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the license for the specific language governing permissions and # limitations under the license. # org.apache.logging.log4j.web.Log4jServletContainerInitializer
I've been reading JBoss deployer source code and I found it always read first row of service file // this line from ServletContainerInitializerDeploymentProcessor.loadSci() String servletContainerInitializerClassName = reader.readLine();
so when I manually edit the service file and just keep the last line (org.apache.logging.log4j.web.Log4jServletContainerInitializer) it works fine now
In anycase, I did revert my log4j2 version to 2.0.2 and it's working as well.
Upvotes: 2
Reputation: 3145
Appears to be a bug in version 2.1. I rolled back Log4j2 to version 2.0.1 and everything works fine.
Upvotes: 1