【问题标题】:Adding extra information to mule loggers向 mule loggers 添加额外信息
【发布时间】:2017-05-26 08:12:37
【问题描述】:

我想为每个请求添加一些关联 ID,并自动显示在日志消息中。如何或多或少地自动为<logger /> 及其变体添加额外的值?

我试过了:

  1. Spring aop 切入 LoggerMessageProcessor.process(MuleEvent event),但该事件不包含记录的消息
  2. Spring aop 切入将包含消息的LoggerMessageProcessor.setMessage(String msg),但由于某种原因未调用该方法

【问题讨论】:

    标签: java spring logging mule spring-aop


    【解决方案1】:
    <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>
    

    【讨论】:

    • 谢谢。其实我自己也能找到解决办法,但这绝对可以用来简化它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    • 1970-01-01
    • 2021-04-29
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多