You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Thorsten Heit (Jira)" <ji...@apache.org> on 2022/11/07 20:55:00 UTC
[jira] [Commented] (LOG4J2-3627) PatternLayout: %xEx{ [ "short" | depth]} not working
[ https://issues.apache.org/jira/browse/LOG4J2-3627?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17630027#comment-17630027 ]
Thorsten Heit commented on LOG4J2-3627:
---------------------------------------
You can verify this behaviour with the following short program:
{code:java}
package com.example.example;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class App
{
public static final Logger LOG = LogManager.getLogger();
private static int count = 0;
private static void doWork() throws Exception {
System.out.println("Count: " + count++);
if (count < 50) {
doWork();
} else {
throw new Exception("Limit reached");
}
}
public static void main( String[] args )
{
try {
doWork();
} catch (Exception ex) {
LOG.catching(ex);
}
}
}
{code}
Configuration for testing:
{code:xml}
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="warn" strict="true">
<Appenders>
<Console name="stdout" target="SYSTEM_OUT">
<PatternLayout pattern="%d{DEFAULT} %-5level %logger(:%L) - %msg%n%xEx{3}" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="stdout" />
</Root>
</Loggers>
</Configuration>
{code}
Using Log4j2 2.10.0 the output is:
{noformat}
(...)
Count: 46
Count: 47
Count: 48
Count: 49
2022-11-07 21:51:48,902 ERROR com.example.example.App(:25) - Catching
java.lang.Exception: Limit reached
at com.example.example.App.doWork(App.java:17) ~[classes/:?]
at com.example.example.App.doWork(App.java:15) ~[classes/:?]
{noformat}
Using a newer version I expect the same, but instead the whole stack trace is shown; tested with 2.11.0 and 2.19.0.
> PatternLayout: %xEx{ [ "short" | depth]} not working
> ----------------------------------------------------
>
> Key: LOG4J2-3627
> URL: https://issues.apache.org/jira/browse/LOG4J2-3627
> Project: Log4j 2
> Issue Type: Bug
> Components: Layouts
> Affects Versions: 2.11.0, 2.11.1, 2.11.2, 2.12.0, 2.12.1, 2.13.0, 2.13.1, 2.13.2, 2.14.0, 2.13.3, 2.14.1, 2.15.0, 2.16.0, 2.17.1, 2.17.0, 2.12.3, 2.12.2, 2.18.0, 2.12.4, 2.17.2, 2.19.0
> Reporter: Thorsten Heit
> Priority: Minor
>
> According to the documentation the patterns {{{}%xEx{short{}}}} or {{{}%xEx{<num>{}}}} should limit the number of lines of a stack trace that is logged. This doesn't work; instead, the complete stack trace is logged (always!). This is in contrary to the patterns {{%ex}} or {{%rEx}} where this works.
> In commit 9ff63b2e50be754ae394feda2c33d9e64fd0ab3a (2018-01-25) a change was implemented because of LOG4J2-2195 (according to the commit message) that removed the option of limiting the number of lines to output.
> Therefore all versions since 2.11.0 should be affected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)