ppkarwasz commented on issue #3809: URL: https://github.com/apache/logging-log4j2/issues/3809#issuecomment-3053462603
Hi @vy, The implementation looks good overall. However, you should also override [`LogEventPatternConverter#handlesThrowable()`](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/pattern/LogEventPatternConverter.html#handlesThrowable%28%29) to ensure exceptions are handled correctly by the layout. The motivation behind `%wEx` and `%xwEx` seems to be to support a logging format, where exceptions are visually separated from the log message by a blank line. For example: ``` 2025-07-09T18:50:02,060 INFO Main - Hello, world! ``` and when an exception occurs: ``` 2025-07-09T18:50:02,059 ERROR Main - An exception occurred. java.lang.RuntimeException: This is a test exception at eu.copernik.sandbox.Main.createException(Main.java:18) at eu.copernik.sandbox.Main.main(Main.java:13) Caused by: java.lang.RuntimeException: Caused by another exception at eu.copernik.sandbox.Main.createNestedException(Main.java:22) ... 2 more Caused by: java.lang.RuntimeException: Root cause at eu.copernik.sandbox.Main.createRootCause(Main.java:26) ... 3 more ``` While this formatting could theoretically be achieved using something like: ```xml <PatternLayout pattern="%d %-5p %c{1.} - %m%n%notEmpty{%n%ex%n}" alwaysWriteExceptions="false"/> ``` there's a caveat: [`VariablesNotEmptyReplacementConverter`](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/pattern/VariablesNotEmptyReplacementConverter.html) does **not** implement `handlesThrowable()`, so Log4j will still append `%ex` unless `alwaysWriteExceptions="false"` is set explicitly on the layout. > [!NOTE] > The `%wEx` and `%xwEx` converters may also have been introduced as Log4j 2 Core equivalents to similar converters provided by Spring Boot's Logback integration. -- 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: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org