File size: 1,160 Bytes
408b7e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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