16 - Centralized Logging

Overview

OpenAlgo implements centralized logging with configurable levels, file rotation, and structured output. All application logs are routed through a unified logging system stored in logs.db and optional file logs.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                        Centralized Logging Architecture                       │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                          Application Components                              │
│                                                                              │
│  ┌────────────┐  ┌────────────┐  ┌────────────┐  ┌────────────┐            │
│  │  Flask     │  │  REST API  │  │  WebSocket │  │  Services  │            │
│  │  Routes    │  │  Endpoints │  │  Proxy     │  │            │            │
│  └─────┬──────┘  └─────┬──────┘  └─────┬──────┘  └─────┬──────┘            │
│        │               │               │               │                    │
│        └───────────────┴───────────────┴───────────────┘                    │
│                                    │                                         │
│                                    ▼                                         │
│                          ┌─────────────────┐                                │
│                          │  get_logger()   │                                │
│                          │  (utils/logging)│                                │
│                          └────────┬────────┘                                │
└───────────────────────────────────┼─────────────────────────────────────────┘

                    ┌───────────────┴───────────────┐
                    │                               │
                    ▼                               ▼
┌────────────────────────────┐    ┌────────────────────────────┐
│      Console Handler       │    │       File Handler         │
│                            │    │    (if LOG_TO_FILE=True)   │
│  - Colored output          │    │                            │
│  - Level-based formatting  │    │  - Rotating files          │
│  - Immediate display       │    │  - Configurable retention  │
└────────────────────────────┘    └────────────────────────────┘


                                  ┌────────────────────────────┐
                                  │       log/ directory       │
                                  │                            │
                                  │  - openalgo.log            │
                                  │  - openalgo.log.1          │
                                  │  - openalgo.log.2          │
                                  └────────────────────────────┘

Configuration

Environment Variables

Usage

Getting a Logger

Log Levels

Level
Value
Use Case

DEBUG

10

Detailed debugging information

INFO

20

General operational messages

WARNING

30

Something unexpected happened

ERROR

40

Error occurred, operation failed

CRITICAL

50

System is unusable

Implementation

Location: utils/logging.py

Log Categories

Application Logs

Category
Logger Name
Description

Auth

blueprints.auth

Login/logout events

Orders

restx_api.place_order

Order placement

WebSocket

websocket_proxy

WS connections

Strategy

blueprints.strategy

Strategy execution

Example Log Output

Startup Banner

Output:

File Rotation

Rotation Settings

Setting
Default
Description

Max Size

10 MB

Rotate when file exceeds

Backup Count

14

Number of rotated files to keep

Compression

None

Rotated files are not compressed

Viewing Logs

File Logs

UI Log Viewer

Access log viewer at /logs:

  • Filter by level

  • Search by keyword

  • Date range selection

  • Download logs

Key Files Reference

File
Purpose

utils/logging.py

Logger configuration

blueprints/logging.py

Log viewer UI routes

database/logs_db.py

Log database models

log/

Log file directory

Last updated