alan0428a commented on code in PR #2691:
URL: https://github.com/apache/logging-log4j2/pull/2691#discussion_r1664285750


##########
src/changelog/.2.x.x/fix_throwable_converter_issues.xml:
##########
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="https://logging.apache.org/xml/ns";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+    <issue id="2691" 
link="https://github.com/apache/logging-log4j2/pull/2691"/>
+    <description format="asciidoc">
+        Resolved the lack of support for "filters" in the %ex pattern and 
"depth" in the %xEx pattern.

Review Comment:
   updated



##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableTest.java:
##########
@@ -16,41 +16,109 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import java.util.List;
+import java.util.stream.Stream;
+import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
+import 
org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
+import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
 import org.apache.logging.log4j.core.test.appender.ListAppender;
-import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
-import org.apache.logging.log4j.core.test.junit.Named;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 /**
- * Unit tests for {@code throwable} pattern.
+ * Unit tests for {@code throwable}, {@code rThrowable} and {@code xThrowable} 
pattern.
  */
-@LoggerContextSource("log4j-throwable.xml")
 public class ThrowableTest {
-    private ListAppender app;
-    private Logger logger;
+    static Stream<Arguments> testConverter_dataSource() {
+        final String filters = 
"org.junit,org.apache.maven,sun.reflect,java.lang.reflect";
+        final Integer depth = 5;
+        return Stream.of(
+                // Throwable
+                Arguments.of("%ex", filters, null),
+                Arguments.of("%ex", null, depth),
+                // RootThrowable
+                Arguments.of("%rEx", filters, null),
+                Arguments.of("%rEx", null, depth),
+                // ExtendedThrowable
+                Arguments.of("%xEx", filters, null),
+                Arguments.of("%xEx", null, depth));
+    }
+
+    @ParameterizedTest
+    @MethodSource("testConverter_dataSource")
+    void testConverter(String exceptionPattern, String filters, Integer depth) 
{
+        final String pattern = buildPattern(exceptionPattern, filters, depth);
+        final ConfigurationBuilder<BuiltConfiguration> configBuilder =
+                ConfigurationBuilderFactory.newConfigurationBuilder();
+
+        final String appenderName = "LIST";
+        final Configuration config = configBuilder
+                .add(configBuilder
+                        .newAppender(appenderName, "List")
+                        
.add(configBuilder.newLayout("PatternLayout").addAttribute("pattern", pattern)))
+                
.add(configBuilder.newRootLogger(Level.ALL).add(configBuilder.newAppenderRef(appenderName)))
+                .build(false);
+
+        try (final LoggerContext loggerContext = 
Configurator.initialize(config)) {
+            // Restart logger context after first test run
+            if (loggerContext.isStopped()) {
+                loggerContext.start();
+                loggerContext.reconfigure(config);
+            }
+            final Throwable cause = new NullPointerException("null pointer");
+            final Throwable parent = new 
IllegalArgumentException("IllegalArgument", cause);
+
+            final Logger logger = loggerContext.getLogger("LoggerTest");

Review Comment:
   updated



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to