snoozeml.logging — Structured Logging & Secret Redaction#
Structured logging and credential sanitization utilities for the SnoozeML Python SDK.
Provides a hierarchical logger rooted at "snoozeml", automatic redaction of
API keys and JWT bearer tokens from log records, and a helper to configure
human-readable or JSON-formatted structured output.
- snoozeml.logging.mask_secret(secret)[source]#
Masks a sensitive credential string so raw secrets are never exposed.
- snoozeml.logging.sanitize_text(text, known_secrets=None)[source]#
Scrubs Bearer tokens, API key key-value pairs, and registered secrets from text.
- snoozeml.logging.sanitize_mapping(mapping, known_secrets=None)[source]#
Returns a shallow copy of a dictionary with sensitive keys redacted.
- class snoozeml.logging.RedactingFilter(name='')[source]#
Bases:
FilterLogging filter that strips API keys, JWTs, and registered secrets from log records.
- Parameters:
name (str)
- class snoozeml.logging.StructuredFormatter(*, format_json=False)[source]#
Bases:
FormatterFormats log records as structured key-value lines or JSON objects.
- Parameters:
format_json (bool)
- snoozeml.logging.get_logger(name=None)[source]#
Returns a child logger under the
"snoozeml"hierarchy with secret redaction enabled.- Parameters:
name (str | None) – Sub-module name (e.g.
"client","converters"). IfNone, returns the root"snoozeml"logger.- Returns:
Configured
logging.Loggerinstance.- Return type:
- snoozeml.logging.configure_logging(level=20, *, format_json=False, stream=None)[source]#
Configures structured console or JSON logging for the
snoozemlpackage.- Parameters:
level (int | str) – Logging level (e.g.
logging.DEBUG,"INFO","WARNING").format_json (bool) – If
True, emit single-line JSON records; otherwise emit human-readable structured key-value lines.stream (TextIO | None) – Output stream (defaults to
sys.stderr).
- Returns:
The configured root
"snoozeml"logging.Logger.- Return type: