Skip to content

feat: Add public mask_matches(text, matches) method to AbstractMaskedLogger #45

Description

@W0lfbane

Problem

maskerlogger 1.1.1 provides excellent secret masking for log output via MaskerFormatter/MaskerFormatterJson, but consumers who need to mask arbitrary strings (not log records) have no public API to do so.

AbstractMaskedLogger._mask_secret(self, msg, matches) exists and is fully functional — it applies capture-group-aware masking with configurable redact percentage using a character-position array. However, because it is prefixed with _, it is a private API not intended for external use.

Current workarounds

Consumers must either:

  1. Call _mask_secret directly — brittle, breaks on version bumps, violates encapsulation
  2. Re-implement capture-group-aware masking from scratch — error-prone, duplicates your logic

Proposed solution

Promote _mask_secret to a public method, e.g.:

def mask_matches(self, text: str, matches: list[re.Match]) -> str:

Or if a broader convenience API is preferred:

def mask_text(self, text: str) -> str:
    """Find secrets in *text* and mask them."""
    matches = self.regex_matcher.match_regex_to_line(text)
    return self._mask_secret(text, matches)

Use case

Applications that collect log entries from multiple sources in a central pipeline, where masking must happen at aggregation time rather than at the individual formatter level.

Impact

Low — the implementation already exists (_mask_secret), it just needs a public name. No behavioral change to existing formatters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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