Using logs to debug a Deployment

Tips on how to debug your Deployment using the Deployment Logs API

Overview

It is important that your application makes use of a logger. Connect stores up to 30 days of logs, and they can be accessed and filtered by using Query the Deployment Logs.

When you write logs they are picked up automatically as long as the logs are written to standard output (stdout) or standard error (stderr) streams.

Advice when creating logs

Add logging in the important places of your application, include relevant details, and exclude sensitive information. You should structure the data to be easier to analyze and log at the correct level.

Viewing your application's logs

Once your logs are implemented, you can view them using the Merchant Center or the Query Deployment Logs endpoint of the Connect API.

You can include optional query parameters as follows:

  • applicationName: Filter results by a specific applicationName.
  • startDate: Filter results by defining a start date of the logs up to 30 days ago.
  • endDate: Filter results by defining an end date of the logs.
  • pageToken: For cursor-based pagination.

Example call and response

Query logs between 1 January 2023 and 30 January 2023shell
curl --location 'https://connect.{region}.commercetools.com/{project-key}/deployments/{deployment-id}/logs?startDate=2023-01-01T00%3A00%3A00&endDate=2023-01-30T00%3A00%3A00' \
--header 'Authorization: Bearer {token}' \
--header 'Content-Type: application/json' \
{
"data": [
{
"type": "APPLICATION_TEXT",
"deploymentId": "90fd2cf0-0965-4a42-9472-a30a058eb776",
"applicationName": "service",
"severity": "DEFAULT",
"timestamp": "2023-05-31T17:28:16.479Z",
"details": {
"message": "Service application listening on port 8080"
}
},
{
"type": "APPLICATION_TEXT",
"deploymentId": "90fd2cf0-0965-4a42-9472-a30a058eb776",
"applicationName": "service",
"severity": "DEFAULT",
"timestamp": "2023-05-31T17:28:15.107Z",
"details": {
"message": "sample"
}
},
{
"type": "APPLICATION_TEXT",
"deploymentId": "90fd2cf0-0965-4a42-9472-a30a058eb776",
"applicationName": "service",
"severity": "DEFAULT",
"timestamp": "2023-05-31T17:28:15.107Z",
"details": {
"message": "sample"
}
}
],
"next": null
}