From 95ff5eeaf994370fd27107c07719523f61cd31d3 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Thu, 5 Mar 2026 19:02:06 -0600 Subject: [PATCH] fix: replace print(req.scope) with logger.debug in /api/docs (#21) Co-Authored-By: Claude Sonnet 4.6 --- app/main.py | 54 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/app/main.py b/app/main.py index ab04918..3de0bd3 100644 --- a/app/main.py +++ b/app/main.py @@ -10,38 +10,64 @@ from fastapi.openapi.utils import get_openapi # from fastapi.openapi.docs import get_swagger_ui_html # from fastapi.openapi.utils import get_openapi -from .routers_v3 import current, players, results, schedules, standings, teams, transactions, battingstats, pitchingstats, fieldingstats, draftpicks, draftlist, managers, awards, draftdata, keepers, stratgame, stratplay, injuries, decisions, divisions, sbaplayers, custom_commands, help_commands, views +from .routers_v3 import ( + current, + players, + results, + schedules, + standings, + teams, + transactions, + battingstats, + pitchingstats, + fieldingstats, + draftpicks, + draftlist, + managers, + awards, + draftdata, + keepers, + stratgame, + stratplay, + injuries, + decisions, + divisions, + sbaplayers, + custom_commands, + help_commands, + views, +) # date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}' -log_level = logging.INFO if os.environ.get('LOG_LEVEL') == 'INFO' else logging.WARNING +log_level = logging.INFO if os.environ.get("LOG_LEVEL") == "INFO" else logging.WARNING # logging.basicConfig( # filename=f'logs/database/{date}.log', # format='%(asctime)s - sba-database - %(levelname)s - %(message)s', # level=log_level # ) -logger = logging.getLogger('discord_app') +logger = logging.getLogger("discord_app") logger.setLevel(log_level) handler = RotatingFileHandler( - filename='./logs/sba-database.log', + filename="./logs/sba-database.log", # encoding='utf-8', maxBytes=8 * 1024 * 1024, # 8 MiB backupCount=5, # Rotate through 5 files ) -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") handler.setFormatter(formatter) logger.addHandler(handler) app = FastAPI( # root_path='/api', - responses={404: {'description': 'Not found'}}, - docs_url='/api/docs', - redoc_url='/api/redoc' + responses={404: {"description": "Not found"}}, + docs_url="/api/docs", + redoc_url="/api/redoc", ) -logger.info(f'Starting up now...') +logger.info(f"Starting up now...") app.include_router(current.router) @@ -70,18 +96,20 @@ app.include_router(custom_commands.router) app.include_router(help_commands.router) app.include_router(views.router) -logger.info(f'Loaded all routers.') +logger.info(f"Loaded all routers.") @app.get("/api/docs", include_in_schema=False) async def get_docs(req: Request): - print(req.scope) - return get_swagger_ui_html(openapi_url=req.scope.get('root_path')+'/openapi.json', title='Swagger') + logger.debug(req.scope) + return get_swagger_ui_html( + openapi_url=req.scope.get("root_path") + "/openapi.json", title="Swagger" + ) @app.get("/api/openapi.json", include_in_schema=False) async def openapi(): - return get_openapi(title='SBa API Docs', version=f'0.1.1', routes=app.routes) + return get_openapi(title="SBa API Docs", version=f"0.1.1", routes=app.routes) # @app.get("/api")