Remove loguru and simplify logging setup
This commit is contained in:
+1
-11
@@ -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)
|
||||
|
||||
@@ -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=(
|
||||
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> "
|
||||
"| <level>{level: <8}</level> "
|
||||
"| <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> "
|
||||
"- <level>{message}</level>"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
ALL_METHODS = [
|
||||
"GET",
|
||||
"POST",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -6,7 +6,6 @@ Flask==3.1.2
|
||||
|
||||
# Logging
|
||||
rich==14.1.0
|
||||
loguru==0.7.3
|
||||
|
||||
# Requests
|
||||
requests==2.32.5
|
||||
|
||||
Reference in New Issue
Block a user