learningview / core /logger.py
ArrowDust's picture
LearnView Pro: Clean Production Build
408b7e6
Raw History Blame Contribute Delete
1.16 kB
import logging
import os
import time
from functools import wraps
from config import APP_NAME
# Resolve the level once
LOG_LEVEL_STR = os.getenv("LOG_LEVEL", "DEBUG").upper()
LOG_LEVEL = getattr(logging, LOG_LEVEL_STR, logging.DEBUG)
logging.basicConfig(
level=LOG_LEVEL,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[logging.StreamHandler()]
)
logger = logging.getLogger(APP_NAME)
# --- 🎯 THE CLINICAL INTERFACE ---
def log_clinical_event(event_name: str, details: dict):
"""Specific logger for child assessment events (Ocular/Phonetic)."""
logger.info(f"📊 CLINICAL_EVENT | {event_name} | {details}")
def log_debug(message: str):
"""Replacement for print() statements."""
logger.debug(f"🔍 DEBUG: {message}")
def monitor_perf(func):
"""Decorator to log execution time."""
@wraps(func)
async def wrapper(*args, **kwargs):
start_time = time.perf_counter()
result = await func(*args, **kwargs)
duration = time.perf_counter() - start_time
logger.debug(f"⏱️ PERF | {func.__name__} execution: {duration:.4f}s")
return result
return wrapper