#!/usr/bin/env python
"""
初始化日志系统
"""
import os
from utils.logger import setup_global_logger

def init_logging_system():
    """
    初始化日志系统
    """
    # 从环境变量获取日志配置，如果没有则使用默认值
    log_level = os.getenv("LOG_LEVEL", "INFO")
    log_dir = os.getenv("LOG_DIR", "logs")

    # 尝试从配置文件读取值
    try:
        with open("logging.conf", "r", encoding="utf-8") as f:
            for line in f:
                if line.startswith("LOG_LEVEL="):
                    log_level = line.split("=", 1)[1].strip()
                elif line.startswith("LOG_DIR="):
                    log_dir = line.split("=", 1)[1].strip()
    except FileNotFoundError:
        pass  # 如果配置文件不存在，则使用环境变量或默认值

    # 设置全局日志系统
    logger = setup_global_logger(
        name="ai-chat-api",
        log_level=log_level,
        log_dir=log_dir
    )

    return logger

if __name__ == "__main__":
    logger = init_logging_system()
    logger.info("Logging system initialized successfully")