向 mule 记录器添加额外信息
Adding extra information to mule loggers
我想为每个请求添加一些关联 ID,并自动将其显示在日志消息中。如何自动或多或少地向 <logger />
及其变体添加额外值?
我试过:
- Spring aop 切入
LoggerMessageProcessor.process(MuleEvent event)
,但事件不包含记录的消息
- Spring aop 切入
LoggerMessageProcessor.setMessage(String msg)
将包含消息,但由于某种原因未调用该方法
<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>
我想为每个请求添加一些关联 ID,并自动将其显示在日志消息中。如何自动或多或少地向 <logger />
及其变体添加额外值?
我试过:
- Spring aop 切入
LoggerMessageProcessor.process(MuleEvent event)
,但事件不包含记录的消息 - Spring aop 切入
LoggerMessageProcessor.setMessage(String msg)
将包含消息,但由于某种原因未调用该方法
<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>