Log4j2 - Request support for ThreadContext (MDC)
- Dominant language
- Java
- Stars
- 1.5k
- Forks
- 133
- Avg merge
- 6m
- Merged PRs (30d)
- 7
Description
Hi,
Log4j2 provides a useful ThreadContext class and even more useful CloseableThreadContext.
```
try (CloseableThreadContext.Instance ignored = CloseableThreadContext.put("key", "value")) {
log.atInfo().log("My message");
}
```
The entries will be logged if pattern contains `%X` or `%X{key}`
I read the code comment that you don't want to encourage people to use `log4j specific` (https://github.com/google/flogger/blob/master/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java#L96).
I would like to request you to reconsider. If someone choose flogger but with a log4j2 backend, it usually means IMO that, that someone prefers your API but would like to take advantage of the log4j2 backend.
If you still prefer to prevent ThreadContext by default, please expose an easy way to extend and create a custom log4j2 backend that will allows it.
BTW - The comment mentions that usage of Flogger tags is preferred but I didn't find any documentation or example.
Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.