Example: Log Management REST API
This example shows how to use the cloud operations Log Management REST API to request and retrieve logs from the workflow servers in your cloud subscription.
The example covers getting a list of log requests, discovering
the available log types, requesting and downloading a log, and finally
deleting log requests and the associated log files.
- Before you begin
- All API calls require a valid cross site forgery request (CSRF) token in the IBM®-CSRF-TOKEN header of the call. Obtain a CSRF token by using
POST /instance/services/csrf_token. For more information, see Preventing cross site request forgery. - Display a list of the log retrieval requests on your subscription
- Use the following call to retrieve requests:
You can filter requests by environment, for example, the development environment and include paging:GET /instance/services/logsGET /instance/services/logs/?environment=dev&offset=5&size=10 - Discover the available log types
- Several different types of logs are supported. To get a list of
the log types enabled on your subscription, use the following call:
The list includes the translation-enabled display name for each log type and a list of the available properties.GET /instance/services/log_types - Request a specific log type for an environment
- Use the following call to request a log:
The details of the log request are passed as a JSON object in the request body of the call. For example, to request the logs from the application cluster in the development environment, the body of the call must include the environment and the log type:POST /instance/services/logs
Depending on the properties that are supported for your log type, you can add more filter criteria in the body of the call by setting the corresponding properties in the JSON object. For example, to request an application cluster log containing all logged events between 01:07 PM and 01:17 PM on 16 August 2019 with a log level all, use the following call:POST /instance/services/logs ... { "environment": "dev", "log_type": "AppCluster" }
The response contains the log ID, and the status and details of the log request. You can use the log ID to retrieve the status, the details of the log request, and the log file. If you specify an unsupported property for a log type, the API returns an error. If you don't include all the supported properties, default values are used for the missing properties.POST /instance/services/logs ... { "environment": "dev", "log_type": "AppCluster", "start_time": "2019-08-16T13:17:22.421Z", "duration": 10, "min_log_level": "all" } - Retrieve the requested log
- Check the status of a log retrieval request by adding the log_id parameter
to the GET call:
When the returned log request contains the status of "available", you can use the following call with content-type "application/zip" to retrieve the .zip file containing the logs:GET /instance/services/logs/8015GET /instance/services/logs/8015/file - Delete log requests and associated log files
- Delete log request and log files by using the following call:
DELETE /instance/services/logs/8015