No log4j2 configuration file found. Using default configuration: logging only errors to the console
Problem 1
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Solution 1
To work with version 2 of log4j aka "log4j2"
-Dlog4j.configuration=
should read
-Dlog4j.configurationFile=
- 1.2 manual: http://logging.apache.org/log4j/1.2/manual.html
- 2.x manual: http://logging.apache.org/log4j/2.x/manual/configuration.html
Problem 2
log4j:WARN ....
Solution 2
In your project, uninclude the log4j-1.2 jar and instead, include the log4j-1.2-api-2.1.jar. I wasn't sure how exactly to exclude the log4j 1.2. I knew that what dependency of my project was requiring it. So, with some reading, I excluded a bunch of stuff.
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.10</artifactId>
<version>0.8.2.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
I am not sure which of the exclusions did the trick. Separately, I included a dependency to the 1.2 api which bridges to 2.x.
<!--
http://logging.apache.org/log4j/2.0/manual/migration.html
http://logging.apache.org/log4j/2.0/maven-artifacts.html
Log4j 1.x API Bridge
If existing components use Log4j 1.x and you want to have this logging
routed to Log4j 2, then remove any log4j 1.x dependencies and add the
following.
-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.2</version>
</dependency>
Now, the 1.2 logs which were only going to the console actually flow to our 2.x appenders.
If you don't have the fortune of the log4j-1.2.jar on your classpath as Renko points out in his comment, you will only see the message no log4j2 configuration file found.
This is a problem if there is an error in your configuration file, as you will not be told where the problem lies upon start-up.
For instance if you have a log4j2.yaml file which log4j2 fails to process, because for example, you have not configured a YAML parser for your project, or your config is simply incorrect. You will encounter the no log4j2 configuration file found message, with no further information. This is the case even if you have a valid log4j2.xml file, as log4j2 will only attempt to process the first configuration file it finds.
I've found the best way to debug the problem is to explicitly state the configuration file you wish to use as per the command line argument mentioned above.
-Dlog4j.configurationFile=
Hopefully this will help you pinpoint if the issue is actually caused by your classloader not finding the log4j2 configuration file or something else in your configuration.
Update
You can also use the below property to change the default level of the status logger to get further information:
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=<level>
i had same problem, but i noticed that i have no log4j2.xml in my project after reading on the net about this problem, so i copied the related code in a notepad and reverted the notepad file to xml and add to my project under the folder resources. it works for me.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<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>