Search code examples
loggingmulemulesoftanypoint-studio

MDC Logging With MuleSoft Runtime 4.4


I have problem with MDC in Anypoint Studio. I use new module in Runtime 4.4 to set variable in logger but it dosen't work. In the console I have output like this. But in the documentation I found that logger should also shows me this set variable like this:

INFO 2021-04-08 16:58:26,882 [[MuleRuntime].uber.15: [test-project-app].exmapleFlow.CPU_LITE @18f679] [{correlationId=c85e16c0-98a4-11eb-bc34-cac765a2219b, processorPath=exmapleFlow/processors/2, testVar=testValue}] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Example

enter image description here


Solution

  • You have to edit the log4j2.xml. The default says this:

    [processor: %X{processorPath}; event: %X{correlationId}]
    

    But you need something like this:

    [%MDC]
    

    It's actually in the docs: https://docs.mulesoft.com/mule-runtime/4.4/logging-mdc#example-log4j2-xml-file-configurations