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.
This commit is contained in:
22
src/monitor_service/logging.py
Normal file
22
src/monitor_service/logging.py
Normal file
@@ -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")
|
||||||
Reference in New Issue
Block a user