Pripravujeme pre Vás novú dokumentáciu, aktuálny stav nájdete tu

CDESK LOGGING APPLICATION

FOR SCRIPTS (DOCKER VERSION)

Overview

This application provides visualisation of logs from CDESK scripts and a graphical interface for running them manually. Script logs can be filtered by date, message type (for example INFO, WARNING, ERROR…) and source script. This directory also includes a cron for deleting logs older than 7 days.

Files and directories

app.py

This file contains the application in which the endpoints and the functionality for displaying and filtering logs, as well as for running scripts manually, are defined.

templates

A directory with the various pages of the application.

logs

A directory containing the logs. The logs are split by date of creation. For example, the log file for the date 11/01/2021 will look like 2021-01-11.log. However, the program can process all log files with the .log extension.

Dockerfile

This Dockerfile is needed to set up the container for cleaning logs, in order to remove logs older than 7 days. This recommended functionality removes older script logs and thus frees up the memory they occupy.

Settings and configuration

Python

To run this application, you need to have Python installed on your PC/server. A newer version is recommended, for example 3.11 or 3.12.

Application address and port

The default address of this application is localhost (127.0.0.1) with port 5001. The port can be changed in the app.py file, right at its end, where the application is initialised.

Setup steps
  1. In the root directory of this application (where app.py is located), create a new virtual environment (python -m venv .venv) and activate it (.venv\Scripts\activate for Windows, source .venv/bin/activate for macOS and Linux).
  2. Run pip install -r requirements.txt to install all the dependencies required for this application.
  3. Run python app.py to start this application. In the terminal you will see the application address (by default http://127.0.0.1:5001), where you will find the script logs and can manually run existing CDESK scripts.

It is also recommended to run a Docker container for cleaning logs, so that logs older than 7 days are removed automatically. From the application root directory, use the command: docker rm -f log-cleaner-container && docker build -t log-cleaner . && docker run -d –name log-cleaner-container -v „</path/to/logs>:/app/logs“ log-cleaner

where </path/to/logs> is the path to the logs directory (/logs) in the application root directory.

Notes on the application

This application will only be accessible from the local computer on which it was started. The application address will be printed in the console where you entered the python app.py command; it should be a localhost address with the port you chose (127.0.0.1:<your port>). If more people will be working with the application, it is recommended to run it on some server/virtual machine.

Using the application

The application has 2 main parts – displaying logs and running scripts manually. After going to the application home page (by default 127.0.0.1:5001) you will be redirected to /logs, where the script logs are displayed. To run scripts manually, go to the /run-scripts page. For easier navigation, use the navigation bar at the top of the page.

Script logs

In the application you can set various filters to display only part of the logs. These filters include date, message type, script name and the number of logs displayed per page.

Whenever a new filter is applied or new logs are added by another script, the log list should be reloaded by pressing the „Filter“ button to apply the changes.

Running a script manually

On this page of the application you can run any existing container with a script whose name begins with ‚cdesk-script‘. If the container is stopped, it will be started. Otherwise, if it is already running, it will execute the command python3 /app/main.py within the container. It is therefore important to meet these two conditions for your own scripts to be displayed and run correctly:

  • The container name begins with ‚cdesk-script‘
  • The file for running the script is named ‚main.py‘