From e7ab5bf57ddb90543a34cf22e1c5884080d04601 Mon Sep 17 00:00:00 2001 From: demo-bot Date: Sun, 9 Aug 2026 15:41:12 +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. --- app/logging_config.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/logging_config.py diff --git a/app/logging_config.py b/app/logging_config.py new file mode 100644 index 0000000..7e995ed --- /dev/null +++ b/app/logging_config.py @@ -0,0 +1,43 @@ +import json +import logging +from urllib.parse import urlsplit, urlunsplit + + +SENSITIVE_KEYS = {"url", "location"} + + +def redact_url(value: str) -> str: + try: + parts = urlsplit(value) + if not parts.scheme or not parts.hostname: + return "[redacted]" + host = parts.hostname + if ":" in host: + host = f"[{host}]" + if parts.port: + host = f"{host}:{parts.port}" + return urlunsplit((parts.scheme, host, parts.path, "", "")) + except (TypeError, ValueError): + return "[redacted]" + + +class JsonFormatter(logging.Formatter): + def format(self, record: logging.LogRecord) -> str: + payload: dict[str, object] = { + "level": record.levelname, + "logger": record.name, + "message": record.getMessage(), + } + fields = getattr(record, "fields", {}) + if isinstance(fields, dict): + for key, value in fields.items(): + payload[key] = redact_url(str(value)) if key in SENSITIVE_KEYS else value + return json.dumps(payload, default=str, separators=(",", ":")) + + +def configure_logging(level: str) -> None: + handler = logging.StreamHandler() + handler.setFormatter(JsonFormatter()) + root = logging.getLogger() + root.handlers = [handler] + root.setLevel(level)