[slf4j-dev] [JIRA] Updates for SLF4J-557: MDCCloseable: not a great fit for a try-with-resources statement
slf4j developers list
slf4j-dev at qos.ch
Thu Mar 23 13:40:00 CET 2023
SLF4J / SLF4J-557 [In Progress]
MDCCloseable: not a great fit for a try-with-resources statement
==============================
Here's what changed in this issue in the last few minutes.
There is 1 comment.
View or comment on issue using this link
https://jira.qos.ch/browse/SLF4J-557
==============================
1 comment
------------------------------
Alberto Scotto on 23/Mar/23 13:28
To make things more clear.
Given the following test:
{code:java}
@Test
public void test() {
try (MDC.MDCCloseable ignored = MDC.putCloseable("k", "val")) {
log.info("BEGIN try");
throw new RuntimeException();
} catch (Exception e) {
log.error("FAILED try", e); // MDC will not be attached to this log at runtime!
}
}{code}
Actual logs produced:
{noformat}
2023-03-23 13:21:37,535 INFO MyTest k=val - BEGIN try
2023-03-23 13:21:37,537 ERROR MyTest k= - FAILED try
{noformat}
Expected:
{noformat}
2023-03-23 13:21:37,535 INFO MyTest k=val - BEGIN try
2023-03-23 13:21:37,537 ERROR MyTest k=val - FAILED try{noformat}
==============================
This message was sent by Atlassian Jira (v9.6.0#960000-sha1:a3ee8af)
More information about the slf4j-dev
mailing list