ZONOS3-Mini / logging_setup.py
fffiloni's picture
Polish responsive layout, redact URL query logs, and record live validation
c392a82 verified
Raw History Blame Contribute Delete
658 Bytes
"""Keep lifecycle/status diagnostics without logging URL query credentials."""
import logging
import re
class QueryRedactingFormatter(logging.Formatter):
def format(self, record):
message = super().format(record)
return re.sub(r'(https?://[^\s?"<>]+)\?[^\s"<>]+', r'\1?[redacted]', message)
def configure_logging():
pattern = "%(asctime)s %(name)s %(levelname)s %(message)s"
logging.basicConfig(level=logging.INFO, format=pattern)
# Format after exception rendering too; preserve method, path and HTTP status.
for handler in logging.getLogger().handlers:
handler.setFormatter(QueryRedactingFormatter(pattern))