-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LOGBACK-1337 LogbackMDCAdapter should store mdc in LinkedHashMap to predict order of MDC in %X #473
base: master
Are you sure you want to change the base?
Conversation
Hi Craig, |
That's right! I noticed that MDC iteration order is pseudorandom when working with logstash/logstash-logback-encoder. This surprised me a bit so I searched to see if anyone had written about it and I found LOGBACK-1337. |
fb2ce09
to
15d4043
Compare
…redict order of MDC in %X Signed-off-by: Craig P. Motlin <cmotlin@gmail.com>
@motlin Thank you for this PR. Operations such as get() and put() for However, the need for ordered iteration is duly noted. |
I was hoping to revisit this and see if it could be included. As an example of why it's desirable, I include MDC in my console output... <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%highlight(%-5level) %cyan(%date{HH:mm:ss.SSS, ${LOGGING_TIMEZONE}}) %gray(\(%file:%line\)) [%white(%thread)] %blue(%marker) {%magenta(%mdc)} %green(%logger): %message%n%rootException</pattern>
</encoder>
</appender> And I add context to my MDC. It's not usually in one method, but spread across a few methods in the call stack. Usually the context has some sort of order. The pieces of context added later are more specific than the pieces added earlier. MDC.put("first", "1");
MDC.put("second", "2");
MDC.put("third", "3");
LOGGER.info("Hello, World!"); With the current implementation, MDC gets printed to the console in pseudo-random order.
|
Would output in alphabetical order suffice? |
I think in some cases I could construct MDC key names with numbers inside to make sure they are sortable later. In other cases I think the keys will be unpredictable in advance. I suspect the way I use MDC is pretty common. I attach context about a service request, then about data reads/writes, then about the response. Some of the keys only last for a single log statement, others last for the duration of request. |
No description provided.