Files
BiliNote/backend/main.py
Jefferyhcool 1ebf236f4f feat(app): 添加日志记录功能
- 新增 logger 模块,用于全局日志记录
- 在关键位置添加日志输出,包括事件处理、文件清理、FFmpeg 检查等
- 优化数据库操作,增加日志记录
- 在主程序启动时添加日志输出
2025-04-14 19:50:44 +08:00

44 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import uvicorn
from starlette.staticfiles import StaticFiles
from dotenv import load_dotenv
from app.utils.logger import get_logger
from app import create_app
from app.db.video_task_dao import init_video_task_table
from app.transcriber.transcriber_provider import get_transcriber
from events import register_handler
from ffmpeg_helper import ensure_ffmpeg_or_raise
logger = get_logger(__name__)
load_dotenv()
# 读取 .env 中的路径
static_path = os.getenv('STATIC', '/static')
out_dir = os.getenv('OUT_DIR', './static/screenshots')
# 自动创建本地目录static 和 static/screenshots
static_dir = "static"
if not os.path.exists(static_dir):
os.makedirs(static_dir)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
app = create_app()
app.mount(static_path, StaticFiles(directory=static_dir), name="static")
async def startup_event():
register_handler()
@app.on_event("startup")
async def startup_event():
register_handler()
ensure_ffmpeg_or_raise()
get_transcriber()
init_video_task_table()
if __name__ == "__main__":
port = int(os.getenv("BACKEND_PORT", 8000))
host = os.getenv("BACKEND_HOST", "0.0.0.0")
logger.info(f"Starting server on {host}:{port}")
uvicorn.run("main:app", host=host, port=port, reload=True)