Reputation: 1311
After porting big project to log4j2, i noticed that logging of exceptions doesn't work. Such code
logger.error("Error occurred", e);
doesn't log exception call stack. The log for the above line contains only:
21/07/2013 15:51:34 ERROR [MyTask-1] [MyManager] Error occurred
Please help to configure the logger.
Updated: My log4j2.xml generally looks like this (i removed rest of the appenders and loggers):
<?xml version="1.0" encoding="UTF-8"?>
<configuration name="server" monitorInterval="30">
<appenders>
<!-- ################# All Appender ############################### -->
<RollingFile name="AllAppender" fileName="${sys:workspace}/logs/all.log" filePattern="${sys:workspace}/archive/logs/all_%d{yyyy-MM-dd_HH}.log">
<PatternLayout>
<pattern>%d{dd/MM/yyyy HH:mm:ss} %-5p [%t] [%c{1}] %m%n</pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy max="50"/>
</RollingFile>
</appenders>
<loggers>
<!-- #################################################################################################### -->
<!-- ################################### Loggers definitions ############################################ -->
<!-- #################################################################################################### -->
<logger name="com" level="debug">
<appender-ref ref="AllAppender" />
</logger>
<root level="debug">
<appender-ref ref="AllAppender"/>
</root>
</loggers>
By the way, monitorInterval doesn't work for me. I have to restart tomcat in order to update logger configuration.
Upvotes: 3
Views: 3207
Reputation: 36844
What version of log4j2 are you using? I remember this being an issue in older betas but it was fixed around beta5 or so... If you are using a recent beta, could you file a bug report?
As a workaround you can replace %m%n
at the end of your pattern with %m%ex%n
.
Upvotes: 3