LOGS Monitoring & Logging
Observability — knowing what your system is doing at all times
Learning Objectives
- •Implement structured logging for trading systems
- •Set up monitoring dashboards and alerts
- •Know what metrics to track in production
Explain Like I'm 5
Logging = recording what happened. Monitoring = watching it in real-time. Alerting = getting notified when something goes wrong. Together, they give you OBSERVABILITY — the ability to understand your system's behavior without being physically present. Critical for a 24/7 trading system.
Think of It This Way
Monitoring is like having security cameras for your trading system. Logs are the recorded footage. Alerts are the alarm system. You can't watch 24/7, but you can set up systems that watch for you and notify you when something needs attention.
1What to Log
2Alert Thresholds
Hands-On Code
Structured Trading Logger
import logging
import json
from datetime import datetime
class TradingLogger:
"""Structured logging for trading system."""
def __init__(self, name='v7_engine'):
self.logger = logging.getLogger(name)
handler = logging.FileHandler(f'logs/{name}_{datetime.now():%Y%m%d}.log')
handler.setFormatter(logging.Formatter(
'%(asctime)s | %(levelname)s | %(message)s'
))
self.logger.addHandler(handler)
self.logger.setLevel(logging.INFO)
def log_signal(self, symbol, direction, confidence, l2_decision):
self.logger.info(json.dumps({
'event': 'SIGNAL',
'symbol': symbol,
'direction': direction,
'confidence': confidence,
'l2_decision': l2_decision,
}))
def log_trade(self, symbol, direction, price, sl, tp, volume, pnl_r=None):
self.logger.info(json.dumps({
'event': 'TRADE',
'symbol': symbol,
'direction': direction,
'price': price,
'sl': sl,
'tp': tp,
'volume': volume,
'pnl_r': pnl_r,
}))
def log_risk(self, dd_pct, dd_zone, risk_level, daily_r_used):
level = logging.WARNING if dd_zone != 'NORMAL' else logging.INFO
self.logger.log(level, json.dumps({
'event': 'RISK_STATE',
'drawdown_pct': dd_pct,
'dd_zone': dd_zone,
'risk_level': risk_level,
'daily_r_used': daily_r_used,
}))
def log_alert(self, severity, message, details=None):
level = logging.CRITICAL if severity == 'CRITICAL' else logging.WARNING
self.logger.log(level, json.dumps({
'event': 'ALERT',
'severity': severity,
'message': message,
'details': details,
}))Structured logging (JSON format) makes it easy to parse, search, and analyze logs. Every trade decision should be logged with enough context to reconstruct the reasoning.
Knowledge Check
Q1.Your monitoring shows IC dropped from 0.07 to 0.01 over 2 weeks. What should happen?
Assignment
Implement structured logging for your trading system. Log at least: signals, trades, risk state changes, and errors. Set up 3 alert thresholds (critical, warning, info) and test them.