feat: system logs page + dynamic IV watchlist with auto-add from cycle
Backend:
- DB: add system_logs table (level/source/cycle_id/ticker/message) and
iv_watchlist table (ticker/added_by/is_active); seed builtin 18 tickers
- DBLogHandler attached at startup — all WARNING+ logs auto-persist to DB
- log_system_event() helper for structured manual events
- New router /api/logs: GET with filters (level, source, cycle_id, ticker,
date range), GET /sources, GET /cycles for dropdowns, DELETE /clear
- iv_watchlist now read from DB instead of hardcoded constant; options_vol
watchlist/refresh/bootstrap endpoints all use get_watchlist_tickers()
- New endpoints: POST/DELETE /options-vol/watchlist-tickers/{ticker} to
add/remove tickers; adding triggers background 1-year bootstrap
- auto_cycle: after log_trade_entries(), auto-detect new underlying proxies
not yet in watchlist, add them and bootstrap their IV history
Frontend:
- New page SystemLogs (/logs): log table with level/source/cycle/ticker/date
filters, color-coded rows, expandable JSON details, auto-refresh 30s
- Options Lab: WatchlistManager section — add ticker input, chip list with
builtin/auto/manual color coding, remove button for non-builtins
- Sidebar: Logs Système nav link (ScrollText icon)
- useApi: useSystemLogs, useLogSources, useLogCycles, useClearLogs,
useWatchlistTickers, useAddWatchlistTicker, useRemoveWatchlistTicker
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,30 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from routers import market_data, geopolitical, options, backtest, ai, portfolio, config, patterns, journal, cycle as cycle_router, profiles as profiles_router, reasoning as reasoning_router, knowledge as knowledge_router, options_vol as options_vol_router, analytics as analytics_router, risk as risk_router
|
||||
from routers import logs as logs_router
|
||||
from services.database import init_db, get_config, cleanup_stale_running_cycles
|
||||
import os
|
||||
import logging
|
||||
import uvicorn
|
||||
|
||||
|
||||
class _DBLogHandler(logging.Handler):
|
||||
"""Persist WARNING+ log records to system_logs table."""
|
||||
def emit(self, record: logging.LogRecord):
|
||||
if record.levelno < logging.WARNING:
|
||||
return
|
||||
try:
|
||||
from services.database import log_system_event
|
||||
log_system_event(
|
||||
level=record.levelname,
|
||||
source=record.name,
|
||||
message=self.format(record),
|
||||
cycle_id=getattr(record, "cycle_id", None),
|
||||
ticker=getattr(record, "ticker", None),
|
||||
)
|
||||
except Exception:
|
||||
pass # Never raise from inside a log handler
|
||||
|
||||
app = FastAPI(
|
||||
title="GeoOptions Intelligence",
|
||||
description="Geopolitical Options Trading Cockpit API",
|
||||
@@ -22,7 +42,11 @@ app.add_middleware(
|
||||
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
import logging
|
||||
# Attach DB log handler to root logger (captures WARNING+ from all modules)
|
||||
_db_handler = _DBLogHandler()
|
||||
_db_handler.setFormatter(logging.Formatter("%(message)s"))
|
||||
logging.getLogger().addHandler(_db_handler)
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
init_db()
|
||||
@@ -74,6 +98,7 @@ app.include_router(knowledge_router.router)
|
||||
app.include_router(options_vol_router.router)
|
||||
app.include_router(analytics_router.router)
|
||||
app.include_router(risk_router.router)
|
||||
app.include_router(logs_router.router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
|
||||
Reference in New Issue
Block a user