修改日志级别以及添加banner

This commit is contained in:
Pan Qiancheng 2025-05-06 11:59:03 +08:00
parent 1bb97f78fe
commit 83c243e475
3 changed files with 23 additions and 3 deletions

Binary file not shown.

View File

@ -1,4 +1,5 @@
from fastapi import FastAPI
from contextlib import asynccontextmanager
from app.router import router
from app.utils.response_wrapper import standard_response
from app.exception_handlers import (
@ -9,18 +10,37 @@ from app.exception_handlers import (
from fastapi.exceptions import RequestValidationError
from starlette.exceptions import HTTPException as StarletteHTTPException
@asynccontextmanager
async def lifespan(app: FastAPI):
# 启动时运行的代码
banner = r"""
🚀 Vector Search API is up and running!
📚 Docs: http://localhost:8000/docs
🔍 OpenAPI: http://localhost:8000/openapi.json
📖 ReDoc: http://localhost:8000/redoc
"""
print(banner)
yield # 👈 这里控制 startup 和 shutdown 之间的生命周期
# (可选)关闭时运行的代码
# print("Shutting down Vector Search API...")
app = FastAPI(
title="Vector Search API",
version="1.0.0",
docs_url="/docs",
redoc_url="/redoc",
openapi_url="/openapi.json"
openapi_url="/openapi.json",
lifespan=lifespan
)
# 注册自定义异常处理器
# 注册异常处理器
app.add_exception_handler(RequestValidationError, validation_exception_handler)
app.add_exception_handler(StarletteHTTPException, http_exception_handler)
app.add_exception_handler(Exception, general_exception_handler)
# 注册路由
app.include_router(router)
@app.get("/")

2
run.py
View File

@ -1,4 +1,4 @@
import uvicorn
if __name__ == "__main__":
uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=True)
uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=True, log_level="warning")