mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2026-11-10 11:08:20 +00:00
logger is currently hooking into uvicorn.error https://github.com/ThePhaseless/Byparr/blob/main/src/utils.py#L27 but uvicorn doesn't know that and in run() sets the log level back to INFO. Repro: none of Byparr's (invisible_playwright is a different logger so it does work) logger.debug calls ever actually show, even when LOG_LEVEL is set to debug Separately, logger should probably be Dispatcharr's own instance instead of using uvicorn.error.
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import logging
|
|
import sys
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.gzip import GZipMiddleware
|
|
|
|
from src.consts import HOST, LOG_LEVEL, PORT, VERSION
|
|
from src.endpoints import health_check, router
|
|
from src.middlewares import LogRequest
|
|
from src.owui import router as owui_router
|
|
from src.utils import get_browser, logger
|
|
|
|
LOG_LEVEL_NAME = logging.getLevelName(LOG_LEVEL).lower()
|
|
|
|
logger.info("Using version %s", VERSION)
|
|
logger.info("Log level set to %s", LOG_LEVEL_NAME)
|
|
|
|
app = FastAPI(debug=LOG_LEVEL == logging.DEBUG, log_level=LOG_LEVEL)
|
|
app.add_middleware(GZipMiddleware)
|
|
app.add_middleware(LogRequest)
|
|
|
|
app.include_router(router=router)
|
|
app.include_router(router=owui_router)
|
|
|
|
|
|
async def init():
|
|
"""Initialize the application."""
|
|
async for browser in get_browser():
|
|
await health_check(browser)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Check for --init flag to run the app in development mode
|
|
if "--init" in sys.argv:
|
|
logger.info("Running initialization script...")
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
loop.run_until_complete(init())
|
|
logger.info("Initialization complete.")
|
|
else:
|
|
uvicorn.run(app, host=HOST, port=PORT, log_level=LOG_LEVEL_NAME)
|