import time
from functools import wraps
from ..logger.loggering import server_logger as logger

def track_execution_time(func):
    """
    追踪函数执行时间并通过日志输出的装饰器
    记录函数开始执行、执行完成及耗时（保留两位小数）
    """
    @wraps(func)
    def wrapper(*args, **kwargs):
        logger.info(f"[{func.__name__}] 开始执行")
        start_time = time.perf_counter()
        
        try:
            return func(*args, **kwargs)
        finally:
            duration = time.perf_counter() - start_time
            logger.info(f"[{func.__name__}] 执行完成，耗时: {duration:.2f} 秒")
    
    return wrapper