首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Groovy脚本mule 3.7.3中引发异常时,如何限制错误日志不在日志中打印

在Groovy脚本mule 3.7.3中引发异常时,如何限制错误日志不在日志中打印
EN

Stack Overflow用户
提问于 2017-02-09 14:59:40
回答 2查看 598关注 0票数 0

当我们在Groovy脚本mule中引发异常时,如何限制错误日志不在日志中打印。下面是流程和响应。

代码语言:javascript
运行
复制
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="7475" doc:name="HTTP Listener Configuration"/>
        <flow name="ExceptionTestFlow">
            <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
            <logger level="INFO" doc:name="Logger"/>
            <scripting:component doc:name="Groovy">
                <scripting:script engine="Groovy"><![CDATA[throw new Exception("Invalid Message")]]></scripting:script>
            </scripting:component>
            <catch-exception-strategy doc:name="Catch Exception Strategy">
                <logger message="#[payload]" level="INFO" doc:name="Logger"/>
            </catch-exception-strategy>
        </flow>

Response as follows:

INFO  2017-02-09 12:13:52,928 [[ExceptionTest].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: 
org.mule.DefaultMuleMessage
{
  id=1efcb560-ee93-11e6-a87c-005056880d06
  payload=org.mule.transport.NullPayload
  correlationId=<not set>
  correlationGroup=-1
  correlationSeq=-1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
  INBOUND scoped properties:
    accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    accept-encoding=gzip, deflate, sdch, br
    accept-language=en-US,en;q=0.8
    connection=keep-alive
    host=localhost:7475
    http.listener.path=/test
    http.method=GET
    http.query.params=ParameterMap{[]}
    http.query.string=
    http.relative.path=/test
    http.remote.address=/127.0.0.1:60711
    http.request.path=/test
    http.request.uri=/test
    http.scheme=http
    http.uri.params=ParameterMap{[]}
    http.version=HTTP/1.1
    upgrade-insecure-requests=1
    user-agent=Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
  OUTBOUND scoped properties:
  SESSION scoped properties:
}
ERROR 2017-02-09 12:13:53,305 [[ExceptionTest].HTTP_Listener_Configuration.worker.01] org.mule.exception.CatchMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to invoke ScriptComponent{ExceptionTestFlow.component.693275170}. Component that caused exception is: ScriptComponent{ExceptionTestFlow.component.693275170}. Message payload is of type: NullPayload
Type                  : org.mule.component.ComponentException
Code                  : MULE_ERROR--2
JavaDoc               : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html
Payload               : {NullPayload}
********************************************************************************
Exception stack is:
1. Invalid Message (java.lang.Exception)
  sun.reflect.NativeConstructorAccessorImpl:-2 (null)
2. java.lang.Exception: Invalid Message (javax.script.ScriptException)
  org.codehaus.groovy.jsr223.GroovyScriptEngineImpl:326 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/script/ScriptException.html)
3. Failed to invoke ScriptComponent{ExceptionTestFlow.component.693275170}. Component that caused exception is: ScriptComponent{ExceptionTestFlow.component.693275170}. Message payload is of type: NullPayload (org.mule.component.ComponentException)
  org.mule.component.AbstractComponent:142 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
********************************************************************************
Root Exception stack trace:
java.lang.Exception: Invalid Message
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
      at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
      at Script1.run(Script1.groovy:1)
      at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:323)
      at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:44)
      at javax.script.CompiledScript.eval(CompiledScript.java:92)
      at org.mule.module.scripting.component.Scriptable.runScript(Scriptable.java:287)
      at org.mule.module.scripting.component.ScriptComponent.doInvoke(ScriptComponent.java:78)
      at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:120)
      at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:55)
      at org.mule.component.AbstractComponent$1$1.process(AbstractComponent.java:236)
      at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
      at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
      at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
      at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:88)
      at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
      at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
      at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
      at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
      at org.mule.component.AbstractComponent.process(AbstractComponent.java:154)
      at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
      at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
      at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
      at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
      at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
      at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
      at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
      at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
      at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
      at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:102)
      at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
      at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
      at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
      at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
      at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
      at org.mule.construct.DynamicPipelineMessageProcessor.process(DynamicPipelineMessageProcessor.java:55)
      at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
      at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
      at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
      at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:88)
      at org.mule.processor.BlockingProce...
********************************************************************************

INFO  2017-02-09 12:13:53,334 [[ExceptionTest].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: null

它正在记录错误日志,并将捕获异常策略。在某些情况下,我不想记录错误(例如:整个ERROR block: ERROR 2017-02-09 12:13:53,305 [ExceptionTest.HTTP_Listener_Configuration.worker.01] )日志。你能帮助我们如何忽略打印日志中的错误日志并执行捕获异常策略块吗?注意:我只需要在应用程序级别进行限制。

EN

回答 2

Stack Overflow用户

发布于 2017-02-09 15:20:34

双击catch-exception-strategy组件以查看其属性。然后取消选中日志异常选项。

票数 0
EN

Stack Overflow用户

发布于 2017-02-12 04:47:35

Mule运行时3.7.x在其实现中没有定义logException属性。避免堆栈跟踪的解决方案如下。

在catch- exception notify中定义一个记录器,并设置类别,同时将级别设置为ERROR以通知异常消息。

另外,将应用程序log4j2.xml中的类别"org.mule.exception.CatchMessagingExceptionStrategy“设置为FATAL

如果您想要任何特定异常的堆栈跟踪,请将此记录器放在该块中,

代码语言:javascript
运行
复制
 <logger message="Exceptions message is ... #[org.mule.util.ExceptionUtils.getFullStackTrace(exception)]" level="ERROR"  doc:name="exceptionLogger"/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42130218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档