Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j2 ERROR Unrecognized format specifier [t]

I have a log4j2 configuration file for a web app running on Tomcat 8 that looks like this

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30" status="trace" strict="true">
        <Properties>
                <Property name="logdir">/path/to/log/dir</Property>
                <Property name="filename">somelogfile.log</Property>
        </Properties>
        <Loggers>
                <Logger name="some.package.name" level="debug" additivity="false">
                        <AppenderRef ref="RollingFile"/>
                </Logger>
        </Loggers>
        <Appenders>
                <RollingFile name="RollingFile" fileName="${logdir}/${filename}" filePattern="${logdir}/${filename}.%d{yyyyMMdd}.gz">
                        <PatternLayout>
                                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
                        </PatternLayout>
                        <Policies>
                                <TimeBasedTriggeringPolicy interval="6" modulate="true"/>
                        </Policies>
                </RollingFile>
        </Appenders>
</Configuration>

I see that my web app writes to the log file, but the %t pattern I have for thread name doesn't seem to resolve, so I get log statements like this

2017-06-10 20:34:51,696 DEBUG s.p.n.SomeServlet [%t] some log message

Notice I get %t instead of the thread name

So to troubleshoot this I started Tomcat using the option

-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE

and I see the following messages print in catalina.out when the webapp is deploying and log4j2 is initializing.

ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern
2017-06-10 19:51:14,277 localhost-startStop-1 DEBUG PluginManager 'Converter' found 41 plugins
2017-06-10 19:51:14,609 localhost-startStop-1 ERROR Unrecognized format specifier [t]
2017-06-10 19:51:14,614 localhost-startStop-1 ERROR Unrecognized conversion specifier [t] starting at position 6 in conversion pattern.

my web app has the following jar files among others

WEB-INF/lib/log4j-api-2.8.2.jar
WEB-INF/lib/log4j-core-2.8.2.jar
WEB-INF/lib/log4j-web-2.8.2.jar

Not sure what is causing %t to print instead of the actual thread name.

.

like image 952
pushNpop Avatar asked Jun 11 '17 03:06

pushNpop


3 Answers

In case you are using ShadowJar and Gradle and you don´t have multiple Log4J versions as in other answers assumed, try this which solves the issue (requires Shadow Plugin > 4.0.0, otherwise see this Plugin ):

build.gradle

import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer

shadowJar{
    transform(Log4j2PluginsCacheFileTransformer)
}
like image 134
Marian Klühspies Avatar answered Oct 16 '22 14:10

Marian Klühspies


The only time I've seen something similar was when the classpath contained multiple versions of Log4j2. I didn't investigate to find the root cause though.

like image 7
Remko Popma Avatar answered Oct 16 '22 14:10

Remko Popma


I too experienced this when I had multiple versions of log4j2 running. Check if any of your dependencies pull in duplicate jars..good luck! Can be a nightmare with classloaders!

like image 1
killjoy Avatar answered Oct 16 '22 12:10

killjoy