为mule记录器添加额外信息

时间:2017-01-11 13:41:47

标签: java spring logging mule spring-aop

我想为每个请求添加一些相关ID,并自动显示在日志消息中。如何自动或多或少地为LoggerMessageProcessor.process(MuleEvent event)及其变体添加额外值?

我试过了:

  1. Spring aop切入LoggerMessageProcessor.setMessage(String msg),但事件不包含已记录的消息
  2. Spring aop切入包含该消息的@-webkit-keyframes fadeA { 0% { opacity: 0 } 13.2%,19.8% { opacity: 1; z-index: 5 } 100%,33% { opacity: 0 } } @-webkit-keyframes fadeB { 0%,33% { opacity: 0 } 46.2%,52.8% { opacity: 1; z-index: 5 } 100%,66% { opacity: 0 } } @-webkit-keyframes fadeC { 0%,66% { opacity: 0 } 79.2%,85.8% { opacity: 1; z-index: 5 } 100% { opacity: 0 } } @-webkit-keyframes fadeD { 0%,66% { opacity: 0 } 79.2%,85.8% { opacity: 1; z-index: 5 } 100% { opacity: 0 } } @-moz-keyframes fadeA { 0% { opacity: 0 } 13.2%,19.8% { opacity: 1; z-index: 5 } 100%,33% { opacity: 0 } } @-moz-keyframes fadeB { 0%,33% { opacity: 0 } 46.2%,52.8% { opacity: 1; z-index: 5 } 100%,66% { opacity: 0 } } @-moz-keyframes fadeC { 0%,66% { opacity: 0 } 79.2%,85.8% { opacity: 1; z-index: 5 } 100% { opacity: 0 } } @-moz-keyframes fadeD { 0%,66% { opacity: 0 } 79.2%,85.8% { opacity: 1; z-index: 5 } 100% { opacity: 0 } } @keyframes fadeA { 0% { opacity: 0 } 13.2%,19.8% { opacity: 1; z-index: 5 } 100%,33% { opacity: 0 } } @keyframes fadeB { 0%,33% { opacity: 0 } 46.2%,52.8% { opacity: 1; z-index: 5 } 100%,66% { opacity: 0 } } @keyframes fadeC { 0%,66% { opacity: 0 } 79.2%,85.8% { opacity: 1; z-index: 5 } 100% { opacity: 0 } } @keyframes fadeD { 0%,66% { opacity: 0 } 79.2%,85.8% { opacity: 1; z-index: 5 } 100% { opacity: 0 } } .anm1{ width:100%; position: absolute; top: 3px; left: 0; opacity: 0; -webkit-animation: fadeA ease 15s infinite; -moz-animation: fadeA ease 15s infinite; animation: fadeA ease 15s infinite } .anm2 { width: 100%; position: absolute; top: 3px; left: 0; opacity: 0; -webkit-animation: fadeB ease 15s infinite; -moz-animation: fadeB ease 15s infinite; animation: fadeB ease 15s infinite } .anm3 { width: 100%; position: absolute; top: 3px; left: 0; opacity: 0; -webkit-animation: fadeC ease 15s infinite; -moz-animation: fadeC ease 15s infinite; animation: fadeC ease 15s infinite } .anm4 { width: 100%; position: absolute; top: 3px; left: 0; opacity: 0; -webkit-animation: fadeD ease 15s infinite; -moz-animation: fadeD ease 15s infinite; animation: fadeD ease 15s infinite },但由于某种原因,该方法未被调用

1 个答案:

答案 0 :(得分:2)

<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>