Class

PatternFilter

PatternFilter(regexp, replacement)

Constructor

# new PatternFilter(regexp, replacement)

This class applies a configured RegExp and replacement strategy to redact, mask, or restructure log payloads before they are emitted.

A filter that patches log messages using regular expressions.

sequenceDiagram participant Logger participant Filter as PatternFilter participant RegExp Logger->>Filter: filter(config, message, context) Filter->>RegExp: execute match() alt match found RegExp-->>Filter: captures Filter->>RegExp: replace(message, replacement) RegExp-->>Filter: transformed message else no match RegExp-->>Filter: null end Filter-->>Logger: sanitized message
Parameters:
Name Type Description
regexp RegExp

The expression to use for detecting sensitive or formatted text.

replacement string | ReplacementFunction

The replacement string or a callback that is invoked for each match.

View Source filters/PatternFilter.ts, line 10

Example
const filter = new PatternFilter(/token=[^&]+/g, "token=***");
const sanitized = filter.filter(config, "token=123&user=tom", []);
// sanitized === "token=***&user=tom"

Methods

# filter(config, message, context) → {string}

This method executes PatternFilter.match and, when a match is found, replaces every occurrence using the configured replacement handler.

Applies the replacement strategy to the incoming message.

Parameters:
Name Type Description
config LoggingConfig

The active logging configuration (unused, but part of the filter contract).

message string

The message to be sanitized.

context Array.<string>

The context entries that are associated with the log event.

View Source filters/PatternFilter.ts, line 113

The sanitized log message.

string

# protected match(message) → {RegExpExecArray|null}

This method runs the configured expression, then resets its state so that repeated invocations behave consistently.

Ensures deterministic RegExp matching.

Parameters:
Name Type Description
message string

The message to test for matches.

View Source filters/PatternFilter.ts, line 103

The match result, or null if no match is found.

RegExpExecArray | null