优化入口文件日志输出方式,解决启动日志在终端不显示的问题
This commit is contained in:
parent
3059c81cc9
commit
b0b570b637
@ -5,6 +5,7 @@
|
||||
Jingrow 应用入口
|
||||
"""
|
||||
|
||||
import logging
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from contextlib import asynccontextmanager
|
||||
@ -14,6 +15,8 @@ from jingrow.services.whitelist import router
|
||||
from jingrow.services.scheduler import get_scheduler_status
|
||||
from jingrow.core.hooks.init_hooks import init_hooks
|
||||
|
||||
logger = logging.getLogger("uvicorn.error")
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""应用生命周期管理"""
|
||||
@ -21,29 +24,27 @@ async def lifespan(app: FastAPI):
|
||||
try:
|
||||
# 初始化钩子系统
|
||||
init_hooks()
|
||||
print("钩子系统已初始化")
|
||||
logger.info("钩子系统已初始化")
|
||||
|
||||
# 启动调度器
|
||||
await start_scheduler()
|
||||
print("调度器已启动")
|
||||
logger.info("调度器已启动")
|
||||
|
||||
# 验证调度器状态
|
||||
status = get_scheduler_status()
|
||||
print(f"调度器状态: 运行={status['running']}, 任务数={status['total_jobs']}")
|
||||
logger.info(f"调度器状态: 运行={status['running']}, 任务数={status['total_jobs']}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"启动调度器失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
logger.exception(f"启动调度器失败: {e}")
|
||||
|
||||
yield
|
||||
|
||||
# 关闭事件
|
||||
try:
|
||||
await stop_scheduler()
|
||||
print("调度器已停止")
|
||||
logger.info("调度器已停止")
|
||||
except Exception as e:
|
||||
print(f"停止调度器失败: {e}")
|
||||
logger.exception(f"停止调度器失败: {e}")
|
||||
|
||||
def create_app():
|
||||
"""创建FastAPI应用"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user