-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Logback's throwable-consuming semantics as an option #2381
Add Logback's throwable-consuming semantics as an option #2381
Conversation
The semantics used to determine the `Throwable` attached to a log event changed in Logback 1.1.0 (in the fix to [LOGBACK-873](https://jira.qos.ch/browse/LOGBACK-873)). When there are not enough arguments to the log call to fill both the throwable field and the placeholders contained in the message pattern, Logback 1.1.0 and later prefer to fill the throwable field and leave some placeholders empty. Log4j Core does the opposite choice: it first fills all the placeholders and only fills the throwable field if there is something left. This change allows `log4j-slf4j-impl` and `log4j-slf4j2-impl` users to switch between the two behaviors by setting the property `log4j2.messageFactory` to: ``` org.apache.logging.slf4j.message.ThrowableConsumingMessageFactory ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for taking care of this @ppkarwasz! 💯
I have two nits:
- Would you mind explicitly stating in all newly added Java source files something like the following, please?
This class should be identical to its clone in {@code log4j-slf4j2-impl}.
Any changes made here should be reflected to the other one, and vice versa.
- Would you mind documenting this in the following files, please?
migrate-from-logback.adoc
installation.adoc#impl-logback
…add_logback_throwable_consuming_semantics
@vy,
I don't think this is necessary. Every time one of
I added some documentation to |
The semantics used to determine the
Throwable
attached to a log event changed in Logback 1.1.0 (in the fix to LOGBACK-873).When there are not enough arguments to the log call to fill both the throwable field and the placeholders contained in the message pattern, Logback 1.1.0 and later prefer to fill the throwable field and leave some placeholders empty. Log4j Core does the opposite choice: it first fills all the placeholders and only fills the throwable field if there is something left.
This change allows
log4j-slf4j-impl
andlog4j-slf4j2-impl
users to switch between the two behaviors by setting the propertylog4j2.messageFactory
to:In this PR two choices have been made:
log4j-slf4j-impl
andlog4j-slf4j2-impl
, since it should be mostly required by Logback users during a transition period. Note that Logback's and Log4j's semantics to deal with throwables agree whenever enough arguments are provided. In a second step users can modify their code using Add recipe to clone an exception argument openrewrite/rewrite-logging-frameworks#141, so that it behaves in the same way in Logback and Log4j Core out-of-the-box. However I can also create a newlog4j-message
artifact for this.ParameterizeMessage
instance does not make a difference.Closes #2363