ppkarwasz opened a new pull request, #3919:
URL: https://github.com/apache/logging-log4j2/pull/3919
Historically, throwable pattern converters (`%ex`, `%xEx`, etc.) behaved in
a context-sensitive way:
* If the **preceding formatter’s expansion** did not end with whitespace,
the converter automatically inserted a space before rendering the exception.
In version `2.25.0`, this was changed to insert a **newline** instead of a
space, but the behavior was still dependent on surrounding context.
#### What this change does
This PR removes the context-dependent behavior altogether and makes `%ex`
expansion fully predictable, while remaining backward-compatible:
* When `%ex` is **added implicitly** because `alwaysWriteExceptions=true`:
* If the pattern already ends with `%n`, a plain `%ex` is appended.
* Otherwise, `%notEmpty{%n%ex}` is appended. This ensures exceptions are
always clearly separated from the main log message by a newline, without adding
extra characters when no exception is present.
* When `%ex` is **explicitly included** in the pattern by the user:
* Its expansion is rendered exactly as written in the pattern.
* It will **never** prepend a newline on its own.
#### Why
* Eliminates confusing context-sensitive behavior.
* Makes output consistent and predictable.
* Preserves legacy expectations by only modifying implicitly added `%ex`.
Closes #3873
--
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]