update logger configuration

This commit is contained in:
春河晴
2025-06-11 15:48:59 +09:00
parent 7b4e7b94f8
commit 302240478c
4 changed files with 26 additions and 4 deletions

View File

@@ -1,7 +1,26 @@
import logging
from typing import Callable, Optional
import structlog
# TODO: customize the logger configuration as needed
# TODO: compress the log output
# TODO: output to a file with JSON format
structlog.configure(
processors=[
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=False),
structlog.dev.ConsoleRenderer(),
],
wrapper_class=structlog.make_filtering_bound_logger(logging.NOTSET),
context_class=dict,
logger_factory=structlog.PrintLoggerFactory(),
cache_logger_on_first_use=False,
)
raw_logger = structlog.get_logger()
binds: dict[str, Callable] = {}
@@ -12,5 +31,5 @@ def get_logger(name: Optional[str]):
return raw_logger
logger = binds.get(name)
if logger is None:
binds[name] = logger = structlog.get_logger(name).bind(name=name)
binds[name] = logger = structlog.get_logger(name).bind(logger_name=name)
return logger

View File

@@ -7,6 +7,7 @@ from src.config.config import global_config
global_api = None
def get_global_api() -> MessageServer:
"""获取全局MessageServer实例"""
global global_api

View File

@@ -92,6 +92,7 @@ class Server:
global_server = None
def get_global_server() -> Server:
"""获取全局服务器实例"""
global global_server

View File

@@ -1,7 +1,6 @@
import asyncio
import json
import re
import sys
from datetime import datetime
from typing import Tuple, Union, Dict, Any
import aiohttp
@@ -116,8 +115,10 @@ class LLMRequest:
logger.error(f"原始 model dict 信息:{model}")
logger.error(f"配置错误:找不到对应的配置项 - {str(e)}")
raise ValueError(f"配置错误:找不到对应的配置项 - {str(e)}") from e
except KeyError as e:
logger.warn(f"找不到{model['provider']}_KEY或{model['provider']}_BASE_URL环境变量请检查配置文件或环境变量设置。")
except KeyError:
logger.warn(
f"找不到{model['provider']}_KEY或{model['provider']}_BASE_URL环境变量请检查配置文件或环境变量设置。"
)
self.model_name: str = model["name"]
self.params = kwargs