Pass key-value properties into events in slf4j-reload4j.#394
Pass key-value properties into events in slf4j-reload4j.#394josephw wants to merge 1 commit intoqos-ch:masterfrom
Conversation
Merge MDC and fluent key-value properties together in slf4j-reload4j, so the fluent API can be used with an appropriate Layout. Signed-off-by: Joseph Walton <jwalton@atlassian.com>
2ac1439 to
b1c8d63
Compare
|
This approach has worked well: I've incrementally migrated the codebase away from direct use of Log4j 1.x to pure SLF4J 2.x, without losing any existing structured logging, or needing any whole-codebase changes. It's now possible to move to another logging framework without changing the application code that's producing logs. This is currently implemented with a fork of |
|
@ceki any thoughts on merging this? We've now moved to an all-SLF4J codebase, with key-value pairs for all structured logging, but not having this change upstream means we're on a fork of |
I'm aiming to migrate an existing codebase off Log4j as a logging framework. Logging is through SLF4J, but there's also extensive direct use of Log4j's
org.apache.log4j.MDCto pass values (other thanStrings) through to aLayoutthat produces structured logging output.An incremental migration would be significantly easier if I were able to adopt SLF4J's new fluent API without having to simultaneously change the backend logging framework.
This PR makes exactly that change: the key-value properties from the fluent API are merged into the snapshot of the MDC, leaving the existing logging backend with exactly the same data, while the logging calls lose their direct dependency on Log4j.
It's not clear to me whether this approach was considered and rejected, because it conflates the two different types of property, or whether it's suitable as a general purpose change.