Masse
Masse

Reputation: 4344

Adding extra information to mule loggers

I would like to add some correlation id for each requests and have it shown in the log messages automatically. How do I add an extra value to <logger /> and its variations more or less automatically?

I have tried:

  1. Spring aop cut into LoggerMessageProcessor.process(MuleEvent event), but it the event doesn't contain the logged message
  2. Spring aop cut into LoggerMessageProcessor.setMessage(String msg) which would contain the message, but for some reason the method isn't invoked

Upvotes: 0

Views: 818

Answers (1)

reddy
reddy

Reputation: 46

<flow name="add-correlation-id">
        <scripting:component doc:name="Script">
        <scripting:script engine="groovy">
            <![CDATA[
                String correlationId=message.getInboundProperty('x-request-id');
                if(correlationId==null || correlationId.length() == 0){
                    correlationId = java.util.UUID.randomUUID().toString();
                }
                message.setSessionProperty('requestID',correlationId);
                org.apache.log4j.MDC.put('x-request-id',correlationId);
            ]]>
        </scripting:script>
    </scripting:component>
</flow>

Upvotes: 3

Related Questions