Overview
The bot uses a dual logging system:- Application Logs (
logger.js): Structured JSON logs for events, errors, and state changes - Tick Logger (
tick-logger.js): High-frequency price data capture in JSONL format
data/ directory.
Application Logger
Design
- Levels:
INFO,WARN,ERROR - Output: Both console and file (best-effort)
- Format:
[timestamp] [level] message {context} - File Pattern:
data/logs/bot-YYYY-MM-DD.log
Implementation
Usage
Example Output
Console
File (data/logs/bot-2024-03-15.log)
Identical format to console, but all messages (INFO/WARN/ERROR) go to the same file.
Log Rotation
Files rotate automatically at midnight UTC:Error Handling
Best-Effort File Writes: If file logging fails (e.g., disk full, permission error), the logger continues with console output only:Tick Logger
Design
- Purpose: Capture every BTC price tick (1 per second) for backtesting and analysis
- Format: JSONL (newline-delimited JSON)
- File Pattern:
data/ticks-YYYY-MM-DD.jsonl - Compression: Highly compressible (repetitive structure)
Implementation
Usage
File Format
JSONL Structure
Each line is a standalone JSON object:ts(number): Unix timestamp in millisecondsprice(number): BTC/USD price
Example File (data/ticks-2024-03-15.jsonl)
Analysis Examples
Load Ticks in Python
Compute 5-Min OHLC Bars
Search for Price Spikes
Compression Strategy
Centralized Logging Integration
Ship Logs to Elasticsearch
Use Winston for Production
Replace the minimal logger with Winston for advanced features:Log Analysis
Parse Structured Context
Count Errors by Type
Daily Summary Report
Debugging with Logs
Trace Interval Lifecycle
Reproduce Production Issue
Performance Monitoring
Log Volume
| Component | Logs/Second | Daily Volume (Uncompressed) |
|---|---|---|
| Application | 1-5 | 5-20 MB |
| Tick Logger | 1 | 3.5 MB |
| Total | 2-6 | 8.5-23.5 MB/day |
Disk I/O Impact
- Synchronous writes:
appendFileSync()blocks the event loop (~1ms/write) - Acceptable for low frequency: Application logs are sparse (1-5/sec)
- High frequency: Tick logger writes every second but payload is tiny (40 bytes)
Related
Interval Tracking
State machine generating log events
History Store
Persistent JSON storage for intervals
Metrics
Analyze performance from logs