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 │ │ - Analyzer │ │ - log/*.log │ │
│ │ - cancelorder │ │ orders │ │ - Console │ │
│ │ - modifyorder │ │ - Sandbox │ │ - Rotating │ │
│ │ - Response │ │ trades │ │ │ │
│ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │ │
│ └────────────────────┼────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Main Database (openalgo.db) │ │
│ │ order_logs / analyzer_logs │ │
│ └─────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────┘Log Types
1. API Order Logs
Backend: log_bp, registered with url_prefix="/logs"
React page: /logs/live (/logs itself is the logs index page)
Displays all API request/response pairs for order operations.
2. Analyzer Logs
Backend: analyzer_bp, registered with url_prefix="/analyzer"
React page: /logs/sandbox
Logs from sandbox (analyzer) trading mode, stored in the analyzer_logs table.
3. Application Logs
Location: log/openalgo_<YYYY-MM-DD>.log (directory from LOG_DIR, default log)
File-based logs for debugging and monitoring, written only when LOG_TO_FILE=True. log/errors.jsonl is always written and holds ERROR-and-above records in JSON Lines form.
A consolidated /logging/ page (logging_bp) links the live, analyzer, traffic, latency, and security views.
Database Schema
order_logs Table
analyzer_logs Table
API Endpoints
Get Order Logs
There is no separate JSON endpoint. GET /logs/ returns JSON when the request carries the AJAX header and renders the logs.html template otherwise.
Query Parameters:
page
int
Page number (default: 1)
start_date
string
Start date (YYYY-MM-DD)
end_date
string
End date (YYYY-MM-DD)
search
string
Case-insensitive match on api_type, request, or response
Page size is fixed at 20 rows inside view_logs() and is not a query parameter. When neither start_date nor end_date is given, the query defaults to today in IST.
Response:
request_data and response_data come back as parsed objects, not JSON strings, and strategy is lifted out of the request payload.
Export Order Logs
Accepts the same start_date, end_date, and search parameters, skips pagination, and returns openalgo_logs_<YYYYMMDD_HHMMSS>.csv.
Log Filtering
By API Type
There is no dedicated api_type parameter. The search term is matched case-insensitively against api_type as well as the request and response bodies, so typing an API type filters to it.
placeorder
Order placements
placesmartorder
Smart orders
modifyorder
Order modifications
cancelorder
Order cancellations
cancelallorder
Bulk cancellations
closeposition
Position closures
basketorder, splitorder
Basket and split placements
placegttorder, modifygttorder, cancelgttorder
GTT orders
orderbook, tradebook, positionbook, holdings, funds, quotes, depth, history
Data reads
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
Rotation is time based, not size based: utils/logging.py installs a TimedRotatingFileHandler.
when
midnight
Roll over daily
interval
1
One day per file
backupCount
LOG_RETENTION (default 14)
Files to keep
Compression
None
Plain text, UTF-8
cleanup_old_logs() also deletes files older than LOG_RETENTION days at startup.
Log Format
Viewing Logs
Via Web UI
Navigate to
/logs/liveApply filters as needed
Click row to expand details
Use export for download
Via Command Line
Security Considerations
API Key Redaction
Redaction happens on read, in the log viewer. The stored request_data column holds the serialized payload as submitted.
Access Control
Logs only visible to authenticated users
Session validation required
No public access
Key Files Reference
blueprints/log.py
Order-log viewer and CSV export routes
blueprints/analyzer.py
Analyzer log routes (/analyzer)
blueprints/logging.py
Consolidated /logging/ landing page
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