Reputation: 4344
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:
LoggerMessageProcessor.process(MuleEvent event)
, but it the event doesn't contain the logged messageLoggerMessageProcessor.setMessage(String msg)
which would contain the message, but for some reason the method isn't invokedUpvotes: 0
Views: 818
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