I just want to know the difference between threadContext.put and MDC.put.Because, i believe that both are doing the same operation.
What is the difference between ThreadContext.put() and MDC.Put()?
Asked Answered
Log4j 2 continues with the idea of the MDC and the NDC but merges them into a single Thread Context. The Thread Context Map is the equivalent of the MDC and the Thread Context Stack is the equivalent of the NDC. Although these are frequently used for purposes other than diagnosing problems, they are still frequently referred to as the MDC and NDC in Log4j 2 since they are already well known by those acronyms.
https://logging.apache.org/log4j/2.x/manual/thread-context.html
which means leveraging the threadcontext is the ideal one right –
Riffe
Yes. as per the code MDC is just a layer over ThreadContext - github.com/apache/logging-log4j2/blob/master/log4j-1.2-api/src/… –
Christy
Also if was able to answer your question don't forget to upvote / accept my ans :) –
Christy
sure @saurav. If you feel the question make sense..You can also upvote it. –
Riffe
According to the log4j2 manual:
org.apache.log4j.MDC and org.apache.log4j.NDC have been replaced by the Thread Context.
© 2022 - 2024 — McMap. All rights reserved.