alan0428a commented on PR #2691:
URL: https://github.com/apache/logging-log4j2/pull/2691#issuecomment-2206446614

   @vy 
   Actually `%rEx` and `%xEx` both operate on a `ThrowableProxy` in existing 
implementation. So only `%ex` needs to rely on  `Throwable#printStackTrace()`. 
However, the output of `Throwable#printStackTrace()` looks like below:
   ```
   java.lang.IllegalArgumentException: IllegalArgument
        at 
org.apache.logging.log4j.core.pattern.ThrowableTest.testConverter(ThrowableTest.java:77)
        at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           (too long to paste)
        at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
   Caused by: java.lang.NullPointerException: null pointer
        at 
org.apache.logging.log4j.core.pattern.ThrowableTest.testConverter(ThrowableTest.java:76)
        ... 128 more
   ```
   If we want to do filtering, we can only check if a line contains target 
package in `options.getIgnorePackages()`.(Since we now we can only get the 
whole `StringBuffer` from `StringWriter#getBuffer()`) I am thinking the logic 
be like:
   ```
   final int endIdx = buffer.indexOf(System.lineSeparator(), offset);
   if (ignoreElement(buffer, options.getIgnorePackages(), offset, endIdx) {
   ...
   }
   
   private static boolean ignoreElement(final StringBuffer buffer, final 
List<String> ignorePackages, final int startIdx, final int endIdx) {
           if (ignorePackages != null) {
               final String line = buffer.subString(startIdx, endIdx);
               for (final String pkg : ignorePackages) {
                   if (line.contains(pkg)) {
                       return true;
                   }
               }
           }
           return false;
       }
   ```
   
   Does this sound reasonable?


-- 
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