0

I am aware that MDC is provided by Log4j and is used for the purpose of grouping the related log messages together aiming easier debugging.

But, should MDC only used for that purpose? Is it considered to be a bad practice if I use MDC for keeping small business information in the executing thread. ?

vigamage
  • 1,975
  • 7
  • 48
  • 74
  • 1
    MDC can helpful in multi thread environment. Refer https://www.baeldung.com/mdc-in-log4j-2-logback – DEBENDRA DHINDA Apr 30 '19 at 08:24
  • 1
    Are you talking about specific MDC features or the concept of MDC in general? Note that the facility is intended for *diagnostics*, and hiding critical business information in secret places makes your code difficult to understand and work on. – chrylis -cautiouslyoptimistic- Apr 30 '19 at 09:27

1 Answers1

4

I don't know your scenario. It sounds like you're using MDC for something it is not made for. Except you want to use those business information for log purposes.

There are many ways to keep data in you application. Making a custom ThreadLocal / custom context.

Take a look at Baeldung - ThreadLocal.

Manuel
  • 1,928
  • 2
  • 16
  • 26