From 8299911fc71c46c851c96cd84e0f29bd9633248e Mon Sep 17 00:00:00 2001 From: demo-bot Date: Sun, 9 Aug 2026 15:38:24 +0000 Subject: [PATCH] decomposer: generate deliverable files for Define the service contract and project architecture for the FastAPI endpoint monitoring service.; Implement the typed monitor CRUD API and concurrency-safe in-memory state according to the service design.; Implement secure on-demand endpoint checks with status updates, latency measurement, robust error handling, and redacted structured logs.; Add operational API endpoints and environment-driven runtime configuration to the monitoring service.; Create automated tests for the monitoring service.; Package the service with Docker and developer documentation.; Validate the complete project. --- src/monitor_service/logging.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/monitor_service/logging.py diff --git a/src/monitor_service/logging.py b/src/monitor_service/logging.py new file mode 100644 index 0000000..5d86e0c --- /dev/null +++ b/src/monitor_service/logging.py @@ -0,0 +1,22 @@ +import json +import logging +from urllib.parse import urlsplit, urlunsplit + + +def redact_url(url: str) -> str: + parts = urlsplit(url) + host = parts.hostname or "" + if ":" in host and not host.startswith("["): + host = f"[{host}]" + if parts.port is not None: + host = f"{host}:{parts.port}" + return urlunsplit((parts.scheme, host, parts.path, "", "")) + + +def log_event(logger: logging.Logger, event: str, **fields: object) -> None: + safe = {key: redact_url(str(value)) if key == "url" else value for key, value in fields.items()} + logger.info(json.dumps({"event": event, **safe}, default=str, sort_keys=True)) + + +def configure_logging(level: str) -> None: + logging.basicConfig(level=level.upper(), format="%(message)s")