Anonim
Anonim

Reputation: 93

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

Upvotes: 0

Views: 549

Answers (3)

Aly L.
Aly L.

Reputation: 1

I had the same problem even when I updated the PatternLayout to have MDC.

Turns out, the default log4j ONLY contains the following:

<AppenderRef ref="file"/>

So, the logging variable I'm looking for is only showing up in my app-name.log.

I added a Console entry in my Appenders as follows:

<Appenders>

    <!-- Start of new -->
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="%-5p %d [%t] [%MDC] %c: %m%n"/>
    </Console>
    <!-- End of new -->

    <RollingFile name="file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}app-name.log"
             filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}tracing-module-%i.log">
        <PatternLayout pattern="%-5p %d [%t] [%MDC] %c: %m%n"/>
        <SizeBasedTriggeringPolicy size="10 MB"/>
        <DefaultRolloverStrategy max="10"/>
    </RollingFile>
</Appenders>

And added the following under Loggers:

<!-- Start of new -->
<AppenderRef ref="Console"/> 
<!-- End of new -->

<AppenderRef ref="file"/> 

Changes will now show up in your Studio Console AND in your app-name.log.

Upvotes: 0

Manish Yadav
Manish Yadav

Reputation: 297

You have to change log4j2.xml appender a bit along with %MDC.

Find the below working example link, I am sure it will work if you follow below link .

https://help.mulesoft.com/s/question/0D52T00005aW7E2SAK/mdc-logging-in-mulesoft-runtime-44

Upvotes: 0

Ezequiel Werner
Ezequiel Werner

Reputation: 26

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

Upvotes: 1

Related Questions