Skip to content

Add a stdlib logging.Filter recipe in recipes/ #6

Description

@jieyao-MilestoneHub

What

Add a recipes/logging_filter.py example showing a stdlib logging.Filter that runs redact_args over every log record's args and extra payload before emission.

Expected outcome

  • New file recipes/logging_filter.py (under 60 lines)
  • A RedactionFilter(logging.Filter) subclass with a filter(self, record) method that:
    • If record.args is a Mapping, walks it through redact_args
    • If record.__dict__ contains user-injected extra keys, walks those through redact_args too
    • Returns True (the filter only mutates, never drops)
  • A 10-line usage snippet at the bottom showing logger.addFilter(RedactionFilter())
  • README "Three killer examples" gets a bullet linking to this recipe (or add a "Recipes" section)

Why this is good for newcomers

  • Pure stdlib, no extra deps
  • The filter is small but production-useful
  • Pattern translates directly to OTel attribute redaction (a future recipe)

Pointers

  • Source: src/redactkit/core.pyredact_args is the only API needed
  • See CONTRIBUTING.md for dev setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueWell-scoped for newcomers

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions