Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j2 exception handling not working

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}

Highlightning also don't work in eclipse nor in Kibana(ELK environment).

Can anybody help?

like image 723
Zoltan Avatar asked Oct 27 '25 21:10

Zoltan


1 Answers

Could it be that the %xEx PatternLayout converter doesn't support property substitution in its options?

What if you put the packages you want to filter directly in the filters list?

It may be worth raising a Jira ticket on the Log4j 2 issue tracker for this.

like image 170
Remko Popma Avatar answered Oct 30 '25 23:10

Remko Popma