1

I am working on a dropwizard project. In the config.yml file i am specifying the log format for the console appender using MDC variables. E.g

   appenders:
   - type: console
      logFormat: "date=%d{yyyy-MM-dd HH:mm:ss} username=%mdc{userName} %t %logger{5} - %X{code} message=%msg %n"
      threshold: ${CONSOLE_LOG_LEVEL:-INFO}

However MDC variable returns an empty value in the log. But I can successfully retrieve by MDC.get("userName") somewhere else in the code.

DTNPerera
  • 95
  • 1
  • 12

1 Answers1

0

I observed, there are two possibility for returning empty values.

  1. In your case, first of all add logger in respective code files

    private static final Logger LOGGER = LoggerFactory.getLogger(YourClassName.class);
    

    After that add MDC.put("key", "your Values")

    Finally It is mandatory to call any logger method let say add below statement

    LOGGER.info("Some log Statemenet"); OR debug/error method>=.
    
  2. remove %mdc from logger config file and try with %X{userName}

Try it and let me know.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Rajeev Rathor
  • 1,830
  • 25
  • 20