feat:初始化工程

This commit is contained in:
2025-10-27 19:05:54 +08:00
commit c85f481a18
11 changed files with 429 additions and 0 deletions

33
config/logger_config.py Normal file
View File

@@ -0,0 +1,33 @@
import sys
from loguru import logger
# 日志格式
STDOUT_FORMAT = (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | "
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level>"
)
FILE_FORMAT = (
"{time:YYYY-MM-DD HH:mm:ss.SSS} | "
"{level: <8} | "
"{name}:{function}:{line} - {message}"
)
# 移除默认处理器
logger.remove()
# 添加控制台处理器
logger.add(
sink=sys.stdout,
level="INFO",
format=STDOUT_FORMAT,
colorize=True,
backtrace=True, # 显示完整异常堆栈
diagnose=True, # 显示详细异常信息
)
# 导出配置好的logger
__all__ = ["logger"]

16
config/setting.py Normal file
View File

@@ -0,0 +1,16 @@
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
tcp_host: str
tcp_port: int
mqtt_host: str
mqtt_port: int
class Config:
env_file = ".env" # 指定.env文件路径
case_sensitive = False # 忽略变量名大小写
# 全局配置实例
settings = Settings()