22 - Log Section

Overview

OpenAlgo provides comprehensive log viewing and management through the web interface, supporting both API order logs and general application logs.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                          Log Section Architecture                            │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                           Log Types                                          │
│                                                                              │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐             │
│  │   API Logs      │  │  Analyzer Logs  │  │  Application    │             │
│  │   /logs         │  │                 │  │  Logs           │             │
│  │                 │  │                 │  │                 │             │
│  │  - placeorder   │  │  - Virtual      │  │  - log/*.log    │             │
│  │  - cancelorder  │  │    orders       │  │  - Console      │             │
│  │  - modifyorder  │  │  - Sandbox      │  │  - Rotating     │             │
│  │  - Response     │  │    trades       │  │                 │             │
│  └────────┬────────┘  └────────┬────────┘  └────────┬────────┘             │
│           │                    │                    │                       │
│           └────────────────────┼────────────────────┘                       │
│                                │                                             │
│                                ▼                                             │
│           ┌─────────────────────────────────────────────────────────┐       │
│           │               Logs Database (logs.db)                    │       │
│           │               order_logs / analyzer_logs                 │       │
│           └─────────────────────────────────────────────────────────┘       │
└─────────────────────────────────────────────────────────────────────────────┘

Log Types

1. API Order Logs

Route: /logs

Displays all API request/response pairs for order operations.

2. Analyzer Logs

Route: /analyzer-logs

Logs from sandbox/paper trading mode.

3. Application Logs

Location: log/openalgo.log

File-based logs for debugging and monitoring.

Database Schema

order_logs Table

analyzer_logs Table

API Endpoints

Get Order Logs

Query Parameters:

Parameter
Type
Description

page

int

Page number (default: 1)

per_page

int

Items per page (default: 50)

api_type

string

Filter by API type

start_date

string

Start date (YYYY-MM-DD)

end_date

string

End date (YYYY-MM-DD)

search

string

Search in request/response

Response:

Log Filtering

By API Type

API Type
Description

placeorder

Order placements

placesmartorder

Smart orders

modifyorder

Order modifications

cancelorder

Order cancellations

cancelallorders

Bulk cancellations

closeposition

Position closures

By Date Range

By Search Term

Searches in both request and response JSON data.

Async Logging

Non-Blocking Log Writes

Benefits

  • Request thread not blocked

  • No impact on order latency

  • Guaranteed log capture

Log Viewer Features

React Component

Features

  • Real-time updates

  • Pagination

  • Filtering by type/date

  • Search functionality

  • JSON pretty-print

  • Export capability

File Logging

Configuration

Rotation Settings

Setting
Value
Description

Max Size

10 MB

Rotate when exceeded

Backup Count

14

Files to keep

Compression

None

Plain text

Log Format

Viewing Logs

Via Web UI

  1. Navigate to /logs

  2. Apply filters as needed

  3. Click row to expand details

  4. Use export for download

Via Command Line

Security Considerations

API Key Redaction

Access Control

  • Logs only visible to authenticated users

  • Session validation required

  • No public access

Key Files Reference

File
Purpose

blueprints/logs.py

Log viewer routes

database/apilog_db.py

Order logs model

database/analyzer_db.py

Analyzer logs model

utils/logging.py

Logging configuration

frontend/src/pages/Logs.tsx

React log viewer

Last updated