How to get application logs using cloudhub API

Author: Manish Prabhu

There are two cloudhub APIs to get your deployed application logs.

  1. https://anypoint.mulesoft.com/cloudhub/api/v2/applications/<your-application-instance-name>/deployments?orderByDate=DESC

         The above API gives the output in following format:

         {

    “data”: [

        {

            “deploymentId”: “string”,

            “createTime”: “string”,

            “startTime”: “string”,

            “endTime”: “string”,

            “instances”: [

                {

                    “instanceId”: “string”,

                    “publicIPAddress”: “string”,

                    “status”: “string”,

                    “region”: “string”

                }

            ]

        }

    ],

    “total”: 1

}

The main information that we can get from the above API is deploymentId and instanceId of the application. Other parameters are timing information (createTime, startTime, endTime ), deployment region and status.

  • We will use some information(deploymentId) to get actual logs from cloudhub.

https://anypoint.mulesoft.com/cloudhub/api/v2/applications/<your-application-instance-name>/logs

We will get array of objects as an output in following format:

{

        “recordId”: “string”,

        “deploymentId”: “string”,

        “instanceId”: “string”,

        “line”: 1,

        “event”: {

            “loggerName”: “string”,

            “threadName”: “string”,

            “timestamp”: 1580023352466,

            “message”: “string”,

            “priority”: “string”

        }

    }

Both APIs require basic authentication as authorization mechanism.

Implementation in mule 4 application:

  1. Sample flow:
  • HTTP Request configuration:
  • We need to pass deploymentId(which comes in output of first HTTP request) in body of second request i.e. HTTP POST Request. Hence the transform message component is configured as:
  • The final output of the flow is shown using the transform message component as follows.
  • We can test the final output of the flow using postman request.

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.