Issue
Spring 4.3.30+hibernate 5 application. pom.xml has all the log4j2 dependencies.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>${log4j2.version}</version>
</dependency>
even added log4j2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="TRACE">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%p [%t] %c{1}.%M(%L) | %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
The ERROR i have been getting:
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
What else am i missing here as i keep getting above error even though my pattern doesn't contain the default layout? I was using log4j before migrating to log4j2.Din't plan on migrating to log4j2 but as i had to upgrade spring and hibernate i started getting ERROR StatusLogger No Log4j2 configuration file found. That's when i decided to migrate to log4j2.
Solution
First, lets list your dependencies and what they do:
- log4j-jcl provides an implementation for Apache Commons Logging to route those logging calls to Log4j 2.
- log4j-core is the Log4j 2 implementation.
- log4j-slf4j-impl routes logging calls using the SLF4J API to Log4j 2.
- log4j-api is the Log4j 2 API.
- log4j-1.2-api routes logging calls made using log4j 1.x to Log4j 2.
- log4j-to-slf4j routes logging calls from the Log4j 2 API to SLF4J.
In case it isn't clear from the descriptions, item 6 is going to be a problem. First, you now have 2 implementations of the Log4j 2 API - log4j-core and log4j-to-slf4j. If log4j-to-slf4j were the one to "win" you would end up with logging going nowhere as the calls would bounce between Log4j and SLF4J and back again.
However, if these are in your dependencyManagement section of the the pom that would be a different story as all that does is declare which version of the jars you want to use.
As for the errors you are seeing, that happens because Log4j's core plugins aren't being loaded for some reason. That can happen if you are shading everything into a single jar and didn't include Log4j's Log4jPlugins.dat file.
Answered By - rgoers