I have a log4j2 configuration file for a web app running on Tomcat 8 that looks like this
对于运行在Tomcat 8上的web应用程序,我有一个log4j2配置文件。
<?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
我看到我的web应用程序写到日志文件,但是我对线程名的%t模式似乎并没有解决,因此我得到了这样的日志语句。
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
注意,我得到的是%t而不是线程名。
So to troubleshoot this I started Tomcat using the option
为了解决这个问题,我使用这个选项启动了Tomcat。
-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.
我在卡特琳娜看到了下面的信息。当webapp部署时,log4j2正在初始化。
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应用程序有以下jar文件。
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.
不确定是什么导致%t打印而不是实际的线程名称。
.
。
2 个解决方案
#1
3
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.
我唯一一次看到类似的情况是当类路径包含Log4j2的多个版本时。但我并没有调查找出根本原因。
#2
0
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!
当我有多个版本的log4j2运行时,我也经历过这种情况。检查是否有任何依赖项拉入重复的jar。好运!类加载器可能是一场噩梦!
#1
3
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.
我唯一一次看到类似的情况是当类路径包含Log4j2的多个版本时。但我并没有调查找出根本原因。
#2
0
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!
当我有多个版本的log4j2运行时,我也经历过这种情况。检查是否有任何依赖项拉入重复的jar。好运!类加载器可能是一场噩梦!