log_redaction

Logging filter that redacts API keys in log output.

Attaches to the root logger so all loggers (including httpx/httpcore) have keys partially censored: first 4 chars + ... + last 4 chars.

log_redaction.redact_api_keys(text)[source]

Replace API key values in text with a redacted form.

Return type:

str

Parameters:

text (str)

class log_redaction.ApiKeyRedactionFilter(name='')[source]

Bases: Filter

Logging filter that censors API keys before they reach the handler.

filter(record)[source]

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

Return type:

bool

Parameters:

record (LogRecord)