From 4fdd215938b43f3209181a8b7d6fbcb4de9ee319 Mon Sep 17 00:00:00 2001 From: gabrii Date: Sun, 28 Sep 2025 11:59:11 +0200 Subject: [PATCH] Remove loguru and simplify logging setup --- app/app.py | 12 +---------- app/blueprint.py | 25 ----------------------- app/common/logging.py | 47 ------------------------------------------- requirements/prod.txt | 1 - 4 files changed, 1 insertion(+), 84 deletions(-) diff --git a/app/app.py b/app/app.py index de50d87..44ab8dd 100644 --- a/app/app.py +++ b/app/app.py @@ -1,8 +1,5 @@ """The app module, containing the app factory function.""" -import logging -import sys - from flask import Flask from . import commands @@ -16,9 +13,9 @@ def create_app(config_object="app.settings"): """ app = Flask(__name__.split(".")[0]) app.config.from_object(config_object) + configure_logging(app) register_commands(app) register_blueprints(app) - configure_logger(app) return app @@ -32,10 +29,3 @@ def register_commands(app): """Register Click commands.""" app.cli.add_command(commands.test) app.cli.add_command(commands.lint) - - -def configure_logger(app): - """Configure loggers.""" - handler = logging.StreamHandler(sys.stdout) - if not app.logger.handlers: - app.logger.addHandler(handler) diff --git a/app/blueprint.py b/app/blueprint.py index fff26b0..461b009 100644 --- a/app/blueprint.py +++ b/app/blueprint.py @@ -4,11 +4,7 @@ This module defines the application blueprint, configures logging, and forwards incoming HTTP requests to the configured backend implementation. """ -import sys - from flask import Blueprint, jsonify, request -from loguru import logger -from rich.traceback import install as install_rich_traceback from .auth import require_auth from .azure.adapter import AzureAdapter @@ -22,27 +18,6 @@ from .exceptions import ConfigurationError blueprint = Blueprint("blueprint", __name__) -# Pretty tracebacks for easier debugging -install_rich_traceback(show_locals=False) - - -# Configure Loguru to print colorful logs to stdout -logger.remove() -logger.add( - sys.stdout, - colorize=True, - enqueue=False, - backtrace=False, - diagnose=False, - format=( - "{time:YYYY-MM-DD HH:mm:ss.SSS} " - "| {level: <8} " - "| {name}:{function}:{line} " - "- {message}" - ), -) - - ALL_METHODS = [ "GET", "POST", diff --git a/app/common/logging.py b/app/common/logging.py index cd0c99d..807cf6b 100644 --- a/app/common/logging.py +++ b/app/common/logging.py @@ -17,9 +17,6 @@ from rich.panel import Panel console = Console() -# --- Request logging helpers --- - - def should_redact() -> bool: """Return True if sensitive values should be redacted in logs.""" # Set LOG_REDACT=false to disable redaction (default True) @@ -179,47 +176,3 @@ def log_request(req: Request) -> str: console.print() return request_id - - -# --- SSE logging helpers, keeping for future use if we enable SSE logging --- -# from .sse import SSEEvent -# def _clean_payload(obj: Any) -> Any: -# """Default cleaning to reduce noisy fields in logs. - -# - If obj is a dict, remove top-level 'tools' -# - If it contains a nested 'response' dict, also remove its 'tools' -# Returns a shallow-cleaned copy when applicable; otherwise returns the input unchanged. -# """ -# if not isinstance(obj, dict): -# return obj -# # Shallow copy top-level -# cleaned = {k: v for k, v in obj.items()} -# if "tools" in cleaned: -# cleaned = {k: v for k, v in cleaned.items() if k != "tools"} -# resp = cleaned.get("response") -# if isinstance(resp, dict) and "tools" in resp: -# # Shallow copy nested response to drop tools -# new_resp = {k: v for k, v in resp.items() if k != "tools"} -# cleaned = {**cleaned, "response": new_resp} -# return cleaned - - -# def log_event(ev: SSEEvent) -> None: -# """Pretty-print one SSE event using Rich. - -# - Title reflects whether the event had an 'event' name and its index -# - If payload parses as JSON (ev.json), it is cleaned and printed as JSON; otherwise raw text is printed -# """ -# obj = ev.json -# if obj is not None: -# title = ( -# f"SSE JSON #{ev.index}" if not ev.event else f"SSE {ev.event} #{ev.index}" -# ) -# console.print(Panel.fit(title)) -# console.print_json(data=_clean_payload(obj)) -# else: -# title = f"SSE data #{ev.index}" -# if ev.event: -# title = f"SSE {ev.event} #{ev.index}" -# console.print(Panel.fit(title)) -# console.print(ev.data) diff --git a/requirements/prod.txt b/requirements/prod.txt index 9839992..fc51573 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -6,7 +6,6 @@ Flask==3.1.2 # Logging rich==14.1.0 -loguru==0.7.3 # Requests requests==2.32.5