修改日志级别以及添加banner
This commit is contained in:
parent
1bb97f78fe
commit
83c243e475
Binary file not shown.
24
app/main.py
24
app/main.py
|
|
@ -1,4 +1,5 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
from app.router import router
|
from app.router import router
|
||||||
from app.utils.response_wrapper import standard_response
|
from app.utils.response_wrapper import standard_response
|
||||||
from app.exception_handlers import (
|
from app.exception_handlers import (
|
||||||
|
|
@ -9,18 +10,37 @@ from app.exception_handlers import (
|
||||||
from fastapi.exceptions import RequestValidationError
|
from fastapi.exceptions import RequestValidationError
|
||||||
from starlette.exceptions import HTTPException as StarletteHTTPException
|
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(
|
app = FastAPI(
|
||||||
title="Vector Search API",
|
title="Vector Search API",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
docs_url="/docs",
|
docs_url="/docs",
|
||||||
redoc_url="/redoc",
|
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(RequestValidationError, validation_exception_handler)
|
||||||
app.add_exception_handler(StarletteHTTPException, http_exception_handler)
|
app.add_exception_handler(StarletteHTTPException, http_exception_handler)
|
||||||
app.add_exception_handler(Exception, general_exception_handler)
|
app.add_exception_handler(Exception, general_exception_handler)
|
||||||
|
|
||||||
|
# 注册路由
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue