mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 21:50:28 +02:00
feat: Implement logging filter for successful HTTP access logs and enhance modal styling for better usability
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import atexit
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
@@ -13,6 +14,23 @@ from .conversion_runner import run_conversion_job
|
||||
from .service import build_service
|
||||
|
||||
|
||||
class _SuppressSuccessfulAccessFilter(logging.Filter):
|
||||
"""Filter out successful (HTTP 200) werkzeug access logs."""
|
||||
|
||||
def filter(self, record: logging.LogRecord) -> bool: # pragma: no cover - small utility
|
||||
try:
|
||||
message = record.getMessage()
|
||||
except Exception: # pragma: no cover - defensive
|
||||
return True
|
||||
# Werkzeug access logs include the status code near the end, e.g.
|
||||
# "GET /path HTTP/1.1" 200 -
|
||||
# Treat any 2xx response as success to suppress.
|
||||
return " 200 " not in message and " 201 " not in message and " 204 " not in message
|
||||
|
||||
|
||||
_access_log_filter_attached = False
|
||||
|
||||
|
||||
def _default_dirs() -> tuple[Path, Path]:
|
||||
uploads_override = os.environ.get("ABOGEN_UPLOAD_ROOT")
|
||||
outputs_override = os.environ.get("ABOGEN_OUTPUT_ROOT")
|
||||
@@ -64,6 +82,11 @@ def create_app(config: Optional[dict[str, Any]] = None) -> Flask:
|
||||
|
||||
atexit.register(service.shutdown)
|
||||
|
||||
global _access_log_filter_attached
|
||||
if not _access_log_filter_attached:
|
||||
logging.getLogger("werkzeug").addFilter(_SuppressSuccessfulAccessFilter())
|
||||
_access_log_filter_attached = True
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user