Skip to content

Support for Multiple Regex Patterns in PatternLayout #4015

@Neel1210

Description

@Neel1210

Description:
Currently, users must develop and maintain custom Log4j2 plugins to mask sensitive data (e.g., emails, phone numbers, tokens). This creates significant overhead, especially in microservices architectures, where deploying and updating custom plugin binaries across dozens of services is difficult to manage.

I propose a native feature that allows users to define multiple regex patterns within a single configuration. This would eliminate the need for custom Java code and simplify the rollout of security compliance updates across distributed systems.

Configuration Example ( yml )

    PatternLayout:
      pattern: "%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %c{1} - %msg%n"
      replace:
        - regex: "([A-Za-z0-9._%+-])([A-Za-z0-9._%+-]*)(@[A-Za-z0-9.-]+\\.[A-Za-z]{2,})"
          replacement: "[EMAIL MASKED]"
        - regex: "([A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.)([A-Za-z0-9-_.+/=]+)"
          replacement: "[TOKEN MASKED]"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

To triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions