slf4j icon indicating copy to clipboard operation
slf4j copied to clipboard

SLF4J-522 - Adds NDC.contains() Method

Open mwootendev opened this issue 4 years ago • 4 comments

Updates the NDC class in slf4j-ext to include a static contains() method that can check the existing nested diagnostic context for the presence of a value.

Added unit tests to test the new NDC.contains() method.

mwootendev avatar Sep 09 '21 23:09 mwootendev

@mwootendev Can you kindly describe what type of problems are better solved by NDC instead of MDC?

ceki avatar Sep 10 '21 00:09 ceki

@ceki I've actually found the NDC useful for tracing a path through a system. It serves as a good "how did we get here", especially when there are multiple paths that interface with some common services. For instance, if there is a low-level service for looking up a user, there will probably be multiple higher-level parts of the system that utilize it. If each layer pushes its own NDC context you get a fairly accurate picture of how you got there. For instance, the same logging statement in that user service may end up with different NDCs of [ORDERS USER LOOKUP], [USER REGISTRATION LOOKUP], and [USER ACTIVATION LOOKUP] depending on how that service was reached. This is especially useful for log statements that are not errors and do not have a stack trace.

I tend to differentiate MDC as the "what did we get here", like an order number or user ID. Having the context of "how" can often greatly enhance the value of the "what."

mwootendev avatar Sep 10 '21 01:09 mwootendev

@mwootendev OK, I am still trying to understand. So [ORDERS USER LOOKUP], [USER REGISTRATION LOOKUP], and [USER ACTIVATION LOOKUP] are NDC values?

If so, [ORDERS USER LOOKUP] describes the ORDERS -> USER -> LOOKUP path?

ceki avatar Sep 10 '21 02:09 ceki

@ceki Yes, that would be correct.

mwootendev avatar Sep 10 '21 03:09 mwootendev