logger: add pre-print callback hook + PII redaction filter#328
Merged
Conversation
Add an extensible callback mechanism to CommonLogger: register_callback /
reset_callbacks run each log record through registered callables before it
is printed (record = {level, time, trace, log}). The hook is generic
(redaction, enrichment, routing).
Add redaction_filter(keys, patterns, redact_with='[REDACTED]') built on
that hook: redacts matching field names (case-insensitive, any depth) and
regex value matches. PII redaction with sensible defaults is registered by
default so logs are scrubbed before they reach stdout/CloudWatch; opt out
with ACAI_LOG_REDACTION=off.
Replace the module-level redaction_filter function and the defaults module (module-level functions + vars) with a single RedactionFilter class: keys/patterns/redact_with via **kwargs, callable so an instance is the callback, defaults as class constants, register_default classmethod for the env-gated wiring. Drop descriptive what-docstrings from CommonLogger.
Add a Logging & Redaction section to the README (callback hook + custom filter usage, default-on PII redaction, ACAI_LOG_REDACTION opt-out) and extend the .agents AGENTS.md logger guidance with the same.
Remove the auto-registered default PII filter, the DEFAULT_KEYS / DEFAULT_PATTERNS lists, the register_default classmethod, and the ACAI_LOG_REDACTION env switch. RedactionFilter is now purely opt-in: callers register it with their own keys/patterns. Docs updated to match.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
Adds two things to
acai_aws.common.logger:A generic pre-print callback hook on
CommonLogger.register_callback(callback)/reset_callbacks(). Every log record ({level, time, trace, log}) is passed through the registered callbacks before it is printed; each returns the record to emit. Extension point for redaction, enrichment, or routing.A
RedactionFilterclass built on that hook.RedactionFilter(keys=[...], patterns=[...], redact_with='[REDACTED]'); the instance is callable, so it registers directly as a callback. Redacts matching field names (case-insensitive, any depth) and regex matches in string values.redact_with=''or any string overrides the replacement.Opt-in by design. Nothing is registered automatically and there is no default key/pattern list. A caller wires the filter they want:
Notes
level/time/trace/log) and JSON/PRETTY/INLINE output unchanged; only matching fields/values are rewritten, and only when a filter is registered.callback(record: dict) -> dict. Runs in registration order.log()try/except drops that line rather than emitting it..agents/AGENTS.mdlogger guidance extended.setuptools_scmderives version from tags, so this warrants a minor bump on release (additive feature).Validation
pytest tests/acai_aws: 609 passed (8 new:RedactionFilterunit tests + callback integration tests).pylint acai_aws --recursive=y --fail-under 10: 10.00/10.Part of SWEET-12.