6
votes

I have a mule flow within which I am logging the entire payload in String format by following code snippet

<logger level="ERROR" message="#[payload:java.lang.String]"/>

Now if the error occurs there really is no need to print the entire payload. The payload object in the message is null and the exception payload is populated with the relevant exception in it.

If I can print just the exception payload in String format, that would suffice. Does any one know how to log the exception payload from the message ?

4
you have received two answers below, care to accept one? If not, comment why. - David Dossot

4 Answers

8
votes
    <logger level="ERROR" message=" 
#[groovy:message.getExceptionPayload().getRootException().getMessage()]" /> 

The above code extracts the message related to the cause of exception.

3
votes

Quite simply:

<logger level="ERROR" message="#[exception]"/>
2
votes

small correction in the expression use:

[groovy:message.getExceptionPayload().getRootException().getMessage()]
0
votes

If you want to save error into payload you need to transform it:

%dw 2.0
output application/json
---
{
    error: error.detailedDescription,
    errorType: (error.errorType.namespace default '') ++ ":" ++ (error.errorType.identifier default '') ,
    recoverable: false
}

So, into payload you have your error