You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Zoltán Nébli (JIRA)" <ji...@apache.org> on 2016/09/28 14:20:20 UTC

[jira] [Created] (LOG4J2-1617) PatternLayout Exception handling with filter

Zoltán Nébli created LOG4J2-1617:
------------------------------------

             Summary: PatternLayout Exception handling with filter
                 Key: LOG4J2-1617
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1617
             Project: Log4j 2
          Issue Type: Bug
          Components: Layouts, Pattern Converters
    Affects Versions: 2.6.2
         Environment: Eclipse mars 4.5.2
jdk 1.8.77
mvn 3.2.1
testng 6.9.10
            Reporter: Zoltán Nébli


I am using log4j2 with this 2 dependencies:

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.6.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
        <version>2.6.2</version>
    </dependency>

When I try to log for example an error with a throwable like:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.annotations.Test;

public class Test {

private static final Logger logger = LogManager.getLogger(Test.class);

@Test
public void testSendMessage() throws Exception {
    Exception exception = new Exception("some exception");
    logger.error("error with exception", exception);
}
}

using patternlayout:

<Configuration>
<properties>
    <property name="filters">org.testng,org.apache.maven,sun.reflect,java.lang.reflect</property>
</properties>

<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT" direct="true">
            <PatternLayout pattern="%maxLen{%d{DEFAULT} [%p]  %c{-3}:%L - %enc{%m} %xEx{filters(${filters})}%n}{200}"/>
        </Console>
</Appenders>

<Loggers>
    <logger name="my.test.class.path" level="trace" additivity="false">
        <AppenderRef ref="ConsoleAppender" />
    </logger>
</Loggers>
</Configuration>

Then the filtered packages won't disappear from the stacktrace, I can't even manipulate the stacktrace in any way like maximizing the lines:

%xEx{5}

Output:

2016-09-28 16:16:08,912 [ERROR] myClasspath.Test:20 - error with exception java.lang.Exception: some exception
	at myClasspath.Test... java.lang.Exception: some exception
	at myClasspath.Test.testSendMessage(Test.java:19) [test-classes/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_79]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_79]
	at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_79]
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) [testng-6.9.10.jar:?]
	at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:197) [testng-6.9.10.jar:?]
	at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:175) [spring-test-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209) [testng-6.9.10.jar:?]
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:639) [testng-6.9.10.jar:?]
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820) [testng-6.9.10.jar:?]
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128) [testng-6.9.10.jar:?]
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129) [testng-6.9.10.jar:?]
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112) [testng-6.9.10.jar:?]
	at org.testng.TestRunner.privateRun(TestRunner.java:782) [testng-6.9.10.jar:?]
	at org.testng.TestRunner.run(TestRunner.java:632) [testng-6.9.10.jar:?]
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) [testng-6.9.10.jar:?]
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) [testng-6.9.10.jar:?]
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) [testng-6.9.10.jar:?]
	at org.testng.SuiteRunner.run(SuiteRunner.java:268) [testng-6.9.10.jar:?]
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng-6.9.10.jar:?]
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) [testng-6.9.10.jar:?]
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244) [testng-6.9.10.jar:?]
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1169) [testng-6.9.10.jar:?]
	at org.testng.TestNG.run(TestNG.java:1064) [testng-6.9.10.jar:?]
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113) [testng-6.9.10.jar:?]
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206) [testng-6.9.10.jar:?]
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177) [testng-6.9.10.jar:?]
PASSED: testSendMessage



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org