Skip to main content

How to export logs

The export-logs.py script allows you to retrieve and display logs from a specified environment of a Divio application for a given range of date and time. The logs are fetched from the Divio API and printed to the terminal. Additionally, the logs are saved to a text file for easy search and analysis.

Requirements

Before running the script, ensure you have the following requirements in place:

  1. Python 3.x: The script requires Python 3.x. If you don't have it installed, you can download it from the official Python website.
  2. requests library: The script uses the requests library to make HTTP requests to the Divio API. Install the library by running the following command in your terminal:
pip install requests

Running the Script

  1. Copy the export-logs.py Python script from https://github.com/divio/scripts/blob/export-logs/export-logs.py to any directory on your system.
  2. In the terminal, cd to the directory where you copied the export-logs.py script.
  3. Run the script with the following command, providing the required command-line arguments:
python export-logs.py "2023-08-13T00:00" "2023-08-13T23:00" "live" "APPLICATION_UUID" "YOUR_API_TOKEN"

Replace:

  • "2023-08-13T00:00" with the desired start date and time in the format YYYY-MM-DDThh:mm.
  • "2023-08-13T23:00" with the desired end date and time in the format YYYY-MM-DDThh:mm.
  • "live" with the slug of the environment (e.g., 'live' or 'test').
  • "APPLICATION_UUID" with the UUID of the Divio application containing the target environment. Extract the UUID from the dashboard URL of the application after the /app/ part. For example, if the application URL is https://control.divio.com/o/{uuid}/{uuid}/, the application UUID would be "{uuid}".
  • "YOUR_API_TOKEN" with your Divio API token.

Once executed, the script will display the logs on the console in reverse chronological order, showing each log's timestamp and message. Simultaneously, it will save the logs to a file named logs.txt in the same directory as the script.

The timestamp format in the logs is truncated to milliseconds for a more concise display.