import logging
import sys
import time
from typing import Dict

# 基础logger配置（控制台输出）
_logger = logging.getLogger("huojv")
if not _logger.handlers:
    _logger.setLevel(logging.INFO)
    handler = logging.StreamHandler(sys.stdout)
    fmt = logging.Formatter(fmt='[%(asctime)s] %(levelname)s %(message)s', datefmt='%H:%M:%S')
    handler.setFormatter(fmt)
    _logger.addHandler(handler)

# 简单的节流打印：同一个key在interval秒内只打印一次
_last_log_times: Dict[str, float] = {}

def throttle(key: str, interval_sec: float, level: int, msg: str):
    now = time.time()
    last = _last_log_times.get(key, 0.0)
    if now - last >= interval_sec:
        _last_log_times[key] = now
        _logger.log(level, msg)

# 对外暴露
logger = _logger
