Questions tagged [mdc]

MDC (*mapped diagnostic context*) is a way to attach thread-scoped named identifier that can be added to every log message from that thread.

It is used to provide log messages with information that is unavailable to the scope when log is written.It provides the thread and user context to log messages and hence stamp each log for better tracking.

For example, it can help put Correlation Id to a request’s logs to help filter it out from similar logs at that time (from other quests) and also track it easily when this request hop from service to service by sharing the Correlation Id.

Typical use cases

Useful links

288 questions
8
votes
2 answers

API Logging in Json format

I would like to log API request/response as json format. The expected LogEntry is something like { "timestamp" : "...", "level" : "DEBUG", "headers" : [ "header1" : "value1", "header2" : "value2", "header3" : "value3" ], …
kiran
  • 223
  • 4
  • 12
8
votes
4 answers

How to set a default value against an MDC key in log4j 2?

As in log4j we have an option to set a default value against an MDC key like this - mdc{key:-defaultVal} Do we have something similar in log4j 2 ?
Tanmoy
  • 1,409
  • 3
  • 13
  • 14
8
votes
1 answer

Logback MDC with ThreadPools or Spring Async

I'm trying to determine how thread-safe MDC is when using Cacheable ThreadPools or Spring's Async annotation. I have a method that calls several CompletableFuture<> and executes them using thread pools @Async public CompletableFuture
shinjw
  • 3,329
  • 3
  • 21
  • 42
8
votes
1 answer

Where to clear the requestId from MDC

I'm trying to add a requestId to my web app's logs, as shown here. public class MDCFilter implements ContainerRequestFilter, ContainerResponseFilter { private static final String CLIENT_ID = "client-id"; @Context protected…
garci560
  • 2,993
  • 4
  • 25
  • 34
8
votes
1 answer

Scala Akka Logging with SLF4J MDC

I'm configuring my Akka application to use the SLF4J logger as specified here: http://doc.akka.io/docs/akka/2.3.4/scala/logging.html Underneath the hood, I'm depending on Logback to do the logging. I'm developing a common module for logging purposes…
HiChews123
  • 1,598
  • 4
  • 20
  • 39
7
votes
4 answers

Using MDC in log4j to dynamically name the log file

Is it possible some how to use MDC to name the log file at run time. I have a single web application which is being called by different names at the same time using tomcat docbase. So i need to have separate log files for each of them.
Shamis Shukoor
  • 2,515
  • 5
  • 29
  • 33
7
votes
2 answers

Material design for the web. How to set the position for a mdc.menu?

Material design for the web. How to set the position for a mdc.menu? I will move the mdc-menu from the left, top corner to the right corner. 70px from top and 25px from the right. Please take a look at my sreenshot. How can I change the element…
Aaron
  • 769
  • 1
  • 14
  • 25
7
votes
1 answer

Spring Boot 2 and logback MDC with reactor

I have an application written with spring 5 and reactor. I put in the subscriber context some information such as the user id. Now I want to log this user id. I'm trying with MDC but if the request changes thread I lost the information. How can I…
Luca
  • 321
  • 1
  • 3
  • 16
7
votes
1 answer

Golang Logging with Mapped Diagnostic Context

How can I achieve MDC Logging (Java) in GoLang? I need to add UUIDs in all server logs in order to be able to trace concurrent requests.
Gabe
  • 5,997
  • 5
  • 46
  • 92
7
votes
2 answers

Default log4j MDC value

Does anyone know how to specify a default value for a missing entry in the MDC using log4j's config xml? I have an appender defined in my XML file like so:
Mark W
  • 2,791
  • 1
  • 21
  • 44
6
votes
2 answers

MDC not working with SLF4J

We use SLF4J (with log4j) as our logging framework. We are trying to leverage the MDC feature which as per online documentation is supported by Log4j. MDC does not work when SLF4J is used. However, when log4j is used instead, it works perfectly…
gkari
  • 229
  • 1
  • 7
  • 11
6
votes
2 answers

Logback MDC on Netty or any other non-blocking IO server

Logback MDC (Mapped Diagnostic Context) is leveraging threadLocal (As far as I know) so that it will be accessible on all the log statements executed by the same thread. My question is, will logback MDC work in the non blocking IO server-side…
so-random-dude
  • 15,277
  • 10
  • 68
  • 113
6
votes
1 answer

Spring boot Static inner class not initialised when application starts as a jar

When I start up the my spring boot application via intellij, the following class initialised properly and the log can be seen. but if I run agains the jar from the build, MyCurrentTraceContext seem not initialised and I can't see the log in the…
user1619397
  • 680
  • 2
  • 11
  • 23
6
votes
2 answers

How to get back MDC "inheritance" with modern logback?

After going back to an older project and getting around to update its dependencies I had to realize that logback does not anymore propagate MDCs to children since version 1.1.5:…
dot_Sp0T
  • 389
  • 4
  • 26
6
votes
1 answer

How do I dynamically create log file names in log4j2 using MDC

I'm trying to generate different log files based on values passed through the MDC in log4j . Having tried several approaches, I cant get any to work . Here's how I'm going about it . Within java code . I'm setting a bunch of values within the…
MuleNoob
  • 127
  • 1
  • 6
1
2
3
19 20