mule-basics

2016-10-26T19:05:17.000Z
Tags: mule programming

Starting to use mule at work to create a restful api, the backend uses soap messages that I'm having to convert to json responses.

However I was not able to find any easy way to use the logger component to simply log my data as I transform it.  After some playing around for a little while, I finally was able to figure out how to use the logger component effectively.

basic mule flow: mule

First you need to know what format the item you are trying to log has. If you want to for example to log the payload as is you can use:

<logger message="Current payload is: #[payload]"
level="INFO" doc:name="Logger"/>

this will just try to log out the payload from the current message, you may get a string or an object reference string.  However if you know your value is xml/json and you just want to see that raw value you can then use:

<logger message="#[message.payloadAs(java.lang.String)]"
level="INFO" doc:name="Logger"/>

Which will output the xml/json value. If you know you have json and you want a specific value in that json you can then use:

<logger message="Current payload is: #[json:key]"
level="INFO" doc:name="Logger"/>

where key is he key of the json object/value you want to log.

Last Updated: 5/21/2019, 1:44:44 PM