Message Logging policy is used to logs custom message between policy and flow. We can log information related to request or response. This comes quite handy in case where we want to capture request/response related logs for debugging without changing the code in mule application.
Warning: If the payload is used as part of the logging message or conditional expression while using non repeatable streams, the payload will be consumed by the policy.
Like for below HTTP listener if streaming strategy is change to Non repeatable stream then payload will be lost when request is received by the flow as stream will be consumed by the policy.
To Start with we will create a mule application and connect it with API manager – please see how we can connect the mulesoft application to API Manager
After deployment in Cloudhub the API manager configuration will come as Active
Now we will apply the policy
Select Message Logging
Now update the policy configuration
We can see below properties
- Message – message we want to capture – define in dataweave expression
- Conditional– condition based logging – define in dataweave expression
- Category– categorized the capture logs
- Level– log level
- Before calling API – HTTP request releated logs
- After calling API – HTTP request releated logs
Lets populate the field as per our need
We want to capture payload only when query param – destination is GOA
Now if we test this API in SOAP UI
We can see the logs in Cloudhub
If we change the query param destination value then logs will not appear in Cloudhub
Sample application – sample-rest-service-message-logging
Sample SOAP UI project – sample-rest-service-xml-message-log-soapui-project