How to restrict the ERROR log to be not printed in the logs when we raised exception in the Groovy script mule 3.7.3

南笙酒味 提交于 2019-12-13 07:00:02

问题


How to restrict the ERROR log to be not printed in the logs when we raised exception in the Groovy script mule. The below is the flow and response.

    <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

It is logging ERROR log and It is going to catch exception strategy. In some scenarios I don't want to log the ERROR(eg: entire ERROR block::: ERROR 2017-02-09 12:13:53,305 [[ExceptionTest].HTTP_Listener_Configuration.worker.01] ) log. Could you please some one assist us how to ignore to be printing the ERROR log in the logs and execute the catch Exception strategy block. note: I need to restrict in application level only.


回答1:


Double click the catch-exception-strategy component to view its properties. And then un-check the Log Exceptions option.




回答2:


Mule runtime 3.7.x does not have the logException attribute defined in its implementation. The solution to avoid stack trace is below.

Define a logger inside the catch-exception-strategy and set the category, along with setting the level to ERROR to notify the message of the exception.

Also, set the category "org.mule.exception.CatchMessagingExceptionStrategy" in the application log4j2.xml to be FATAL

If you want the stacktrace of any particular exception, keep this logger inside that block,

 <logger message="Exceptions message is ... #[org.mule.util.ExceptionUtils.getFullStackTrace(exception)]" level="ERROR"  doc:name="exceptionLogger"/>


来源:https://stackoverflow.com/questions/42130218/how-to-restrict-the-error-log-to-be-not-printed-in-the-logs-when-we-raised-excep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!