Tale of Mule Application Logs

Author: Nikhil Balyan

Why do we need to extract Logs from Anypoint Platform?

If we are going with the default deployment strategy of MuleSoft of deploying applications to CloudHub, our logs will be persisted on the CloudHub.

But persisting logs on CloudHub comes along with challenges, as CloudHub stores logs only up to 100 MB per app & per worker for up to 30 days, whichever is hit first.

Log information is of equal importance in all life cycles of the Application right from the Development till Maintenance.

What are the possible ways of persisting logs of applications deployed to CloudHub?

There are many possible ways to persist the logs of an application deployed on CloudHub, but the 2 most popular ones are:

  1. Log Appenders: In this approach, log appenders are used at the application level and the logs are shipped to a different location.
  2. Manually: By manually pulling the logs from the CloudHub and then storing them, so that the logs are not lost.

Automating the Manual Retrieval of Logs

In this blog, we will be focusing on automating the manual approach of retrieving logs by using Anypoint CloudHub API.

Below is the snapshot of the Mule Flow that is used to retrieve the logs and store in a file.

Above orchestration involves following steps to fetch the logs:

Step 1: Set Application Name retrieves the application name from the query param and stores it in a variable.

Step 2: Make a call to Get deployments by domain operation of CloudHub connector to retrieve the deployment details of the application. Now, configure the fields of the operation.

  • Domain: Application Domain Name of the application
  • X anypnt env id: Anypoint Environment ID of the target application environment
  • Limit: Maximum number of deployment to be fetched
  • Offset: Index of the deployment to retrieve, used for pagination
  • Order by date: Order of deployments
  • Logging version: Logging version, by default VERSION_2(if you’re using older version then update accordingly)

Step 3: Store the instance ID of the latest deployment which will be used to fetch all the logs from the Get log files by domain instance id operation of CloudHub connector.

Step 4: Fetch the logs of the latest deployment by making a call to Get log files by domain instance id operation of CloudHub connector(configured in http requester in the screenshot). Configure the fields of the http requester:

  • X-ANYPNT-ENV-ID: part of header, supply with the target application’s environment ID
  • domain: part of URI param, Application Domain Name of the application
  • instanceId: part of URI param, instance ID retrieved in Step 3.

Step 6: Store the log contents at any location.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.