In this article, we are going to discuss configuring the message logs in MuleSoft. This session incorporates the prerequisites, working of policy, the policy parameter configuration, and working with mule message logging. The Message Logging policy logs customized messages based on data from incoming requests, backend answers, or data from other policies that have been applied to the same API endpoint. You can get this course mulesoft training available online which helps you understand the mule platform.Â
Prerequisites
To establish or administer APIs, you must hold the Anypoint Platform Organization Administrators role or have the authority to do so.
How does policy work?
The steps for logging a policy are as follows:
- To the API, a request is issued.
- If the following criteria are met, the message gets logged:
- The logger defined in the log4j2.xml configuration file includes the level and category of the log indicated in the policy.
- Either the policy’s conditional field was not set, or it was set but the condition was not matched.
- The response from the API is returned. The Message Logging Policy does not affect the execution or flow of any policy.
- The error message is recorded in the log of an application.
Policy Parameter Configuration
We can now access the program by passing this client id and secret.
Accessing/Modifying Message Logging
The Message Logging policy is used to keep track of custom messages sent between policies and flows. We can keep track of log information about a request or a response. This is useful if we need to gather request/response related logs for troubleshooting purposes without modifying the mule application’s code.
Note: The payload will be consumed by the policy if it is included in the logging message or conditional expression when utilizing non-repeatable streams.
If the streaming strategy for the below HTTP listener is changed to a Non-repeatable stream, the payload will be lost when the flow receives the request since the stream will be devoured by the policy.
We’ll start by building a mule application and connecting it to API Manager – Please see how the Mulesoft application can be connected to API Manager.
Connecting API Manager to Mulesoft application
API Manager’s auto-discovery feature allows you to manage APIs by connecting a deployed application with a platform-created API.
In this scenario, we’ll utilize Anypoint Studio to deploy the app.
Initially, AnyPoint Studio should be updated with your Anypoint Platform credentials; this is the same credential that would employ your code’s deployment to CloudHub.
We’ll need the AnyPoint platform’s credentials — if you don’t see it, ask the administrator.
Copy the Secret and Client id after clicking on the organization’s name.
In the AnyPoint Studio, update and validate the same.
Now we must construct the application’s API Manager setup.
Create an API Manager setup for the mule app in an API Manager, and the API name would be synchronized with assets that are exchanged.
After you’ve saved, go to Autodiscovery and look for an API ID. Make a note of it. Also, note that the status is now Unregistered.
As noticed in the previous steps, we should add an AutoDiscovery config to the Mule application –Â
Only use AnyPoint Studio to deploy an application now, as this ensures that the secret and client id is delivered to Cloudhub through AnyPoint Studio.
Alternatively, if we would like to deploy a Mulesoft app manually or using Maven, please include the characteristics listed below in the deployment.
Click on the Tab “properties”
anypoint.platform.analytics_base_uri=https://analytics-ingest.anypoint.mulesoft.com/
anypoint.platform.client_id=2ccab1a7dcd94b69b7b1aa93c40af931
anypoint.platform.client_secret=C30fE68A87464438B534eFC47e4da0fB
anypoint.platform.base_uri=https://anypoint.mulesoft.com/
During the logs and the Mule runtime, we can observe the application indicating that API Manager has been registered successfully after it has been deployed.
In addition, we now have access to the endpoint –
If we validate the API manager once again, the status should now be Active, indicating that the application has been registered.
Now, in the API manager, add a client policy for this app.
Choose the origin of a credential.
Click Apply.
We’ll get an authentication issue if we return to the very same endpoint —
Now we’ll construct a credential for the client application to access the application – based on the Exchange access request.
If the SLA tier isn’t specified, the page will be redirected to the Client Application page.
Simply take note of the secret and client id.
We can now access the program by passing this secret and client id.
The API manager configuration will be Active after deployment in Cloudhub.Â
We shall now put the policy into practice.
Message Logging should be selected.
Now the policy settings should be updated.
The properties are listed below.
- Message – specify the message we would like to capture in a dataweave expression
- Conditional – logging depending on conditions – specify in a dataweave expression
- Category – the capture logs were categorized
- Level– log level
- Before calling API – Logs relating to HTTP requests
- After calling API – Logs about HTTP requests
Let’s fill in the fields with the information we require.
We only like to capture payload if query parameters are specified – GOA is the final destination.
Click apply
Now, suppose we use SOAP UI to test this API,
In Cloudhub, we could see the logs.
Logs will not display in Cloudhub when the query param destination value is changed.
Conclusion
This article has shown you how to configure the message logging. By this, you have successfully learned how to capture the requests or responses that aids while debugging the mule application.Â
References
- Message Logging, https://docs.mulesoft.com/api-manager/2.x/message-logging-policy
- Message Logging, https://mulesy.com/message-logging/
API Manager – Auto-Discovery, https://mulesy.com/api-manager-auto-discovery/
Author Bio
I am VarshaDutta Dusa, Working as a Senior Digital Marketing professional & Content writer in HKR Trainings. I Have good experience in handling technical content writing and aspire to learn new things to grow professionally. I am expert in delivering content on the market demanding technologies like mulesoft tutorial, Dell Boomi Tutorial, Elasticsearch Course, Fortinet Course, postgresql,splunk, Success Factor, Denodo, etc. Follow me on linkedin
Discover more from TechBooky
Subscribe to get the latest posts sent to your email.