A logger is usually statically defined in code, which makes the log sometimes difficult to understand.
NDC allows you to dynamically push parameter that will be displayed in each subsequent line of the log issued by the stream, as long as it is a pop ped.
Useful if you want to use the log:
[request=x] a [request=y] a [request=x] b [request=x] c [request=y] b [request=x] d [request=y] c [request=y] d
(Disclaimer: I do not remember the exact formatting)
With just a,b,c,d it's hard to figure out which thread is doing something. If you push and pop the request identifier dynamically, then it is easier to follow. It can also be used for other types of contextual information.
source share