Comments (9)
@mosesn Thank you for your detailed comments. I have added a link to this issue from Changes under consideration for SLF4J version 2.1.0
I was thinking of something similar to your proposition 2 as an extension mechanism for MDC.
Question: How does proposition 2 help in propagating the MDC context to child threads?
Answer: The MDC extension has its own means to extract its own data as appropriate to the current thread, e.g. extreme lengths mentioned earlier.
Thus, if I understand correctly, the MDC extension mechanism allows the user to plugin an external MDC (mapped diagnostic context) into SLF4J's MDC. This achieves the goal of context propagation indirectly by delegating the problem to the extension but without providing a propagation mechanism in SLF4J.
from slf4j.
@mosesn As for the scary message, developers who wish to override mdcAdapter that they might also need to call LoggerContext.setMDCAdapter. Up until 1.5.1, LoggerContext.setMDCAdapter did not allow overriding the mdcAdapter. Commit 097da9dd54c8 changes this.
from slf4j.
Question: How does proposition 2 help in propagating the MDC context to child threads?
Answer: The MDC extension has its own means to extract its own data as appropriate to the current thread, e.g. extreme lengths mentioned earlier.
Yes, that's exactly right. I'm picturing something like MDC.extend(MDCExtension)
that would let a customer register an "external MDC".
@mosesn As for the scary message, developers who wish to override mdcAdapter that they might also need to call LoggerContext.setMDCAdapter. Up until 1.5.1, LoggerContext.setMDCAdapter did not allow overriding the mdcAdapter. Commit 097da9dd54c8 changes this.
Thank you!! I'll definitely use this once it's released.
from slf4j.
@mosesn Would like to try to implement?
from slf4j.
Yep, sure! Is there a branch I should do the work in? And is it acceptable to add a method to Slf4jServiceProvider or MdcAdapter, or would you want me to figure out a way to avoid doing that? (I'm thinking about how to communicate to logback that LoggingContext#mdcAdapter should take the MDCExtension into account)
from slf4j.
I would suggest "branch_2.1.x".
It is OK to add methods to the MDCAdapter interface as long as they have default implementations do something reasonable or in the worst case don't do anything.
from slf4j.
Been looking at this exact question recently. We wrote custom encoders for Logback and Log4j2 to provide standard logging contexts for all applications in our division (> 100 apps). It's been working well except for those few developers using reactive APIs.
My thought for this feature is to update the Log4j API to provide logging overloads that include the reactive context. An equivalent to the MDC pattern, e.g. %Context{foo}
, could be used to include context variables in the logging output. I think it would be up to developers to populate that context and pass it into Slf4j calls. This relieves Slf4j from having to invent a very difficult wheel.
One problem, is think, is that the RxJava context is not a standard item and is not uniformly supported by all applications. It seems the standard projects, e.g. RxJava, cannot see a good way forward, with a couple attempts at solving the problem abandoned over some years.
- 2015: https://github.com/ReactiveX/RxJava/issues/2885
- 2019: https://github.com/ReactiveX/RxJava/issues/6484
There is this specific Open Telemetry extension for Logback, which is doing the necessary context copying:
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/logback/logback-mdc-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/mdc/v1_0/OpenTelemetryAppender.java#L88-L102
I haven't used RxJava/Reactor much. But I have done a mess of asynchronous/non-blocking code in C/C++ over the years. I don't see much hope for standardizing "context local" propagation. Thus, the best way to go for the foreseeable future is to make the logging API explicit wrt reactive context.
from slf4j.
There is support for context also in reactive/non-blocking approach of processing. At least, project-reactor does have it: https://projectreactor.io/docs/core/release/reference/#context
from slf4j.
There is support for context also in reactive/non-blocking approach of processing. At least, project-reactor does have it: https://projectreactor.io/docs/core/release/reference/#context
Exactly. What is missing is a logging API that will include attributes from that context similarly to how existing APIs use MDC. A reactive diagnostic context, if you will.
I'm thinking the context is the 1st parameter to a set of overloads, e.g.
logger.debug(ctx, "foo - bar: {}, biff: {}", bar, biff);
from slf4j.
Related Issues (20)
- MDC Usage regression HOT 10
- [question] How do you pronounce SLF4J?
- Message formatting with last argument being Throwable
- Explicit provider fails when used with module system HOT 4
- Some links from FAQ document don't work. HOT 1
- MavenGate (CVE)
- [Feature Request]: Add error method with varargs and Throwable in Logger interface
- `slf4j-api-2.0.11` throws `java.lang.NullPointerException` in Android build HOT 1
- Deprecate `jcl-over-slf4j` for removal HOT 2
- putCloseable should not remove the key from MDC if it was previously set to a different value
- JUL bridge and System.Logger are inconsistent on handling of OFF and ALL HOT 9
- Wrong classname when using slf4j inside a wrapper and logging via LoggingEventBuilder HOT 6
- slf4j doesn't work on the docker HOT 4
- load slf4j 2.0.x Exceptions in OSGI , the version number and check mode are incorrect.
- SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
- [BUG] - JCL-Over-SLF4J Module Definition does not specify the service loader for JPMS applications HOT 1
- org.slf4j.LoggerFactory (in module org.slf4j) cannot access class org.slf4j.impl.StaticLoggerBinder (JPMS APPLICATION) HOT 2
- Can this Library use in android app ?
- [Feature] 'Strict' startup mode that fails if no or multiple bindings are configured
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slf4j.