# 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.
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. |
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. |
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. |
The match result, or null if no match is found.
RegExpExecArray
|
null