Skip to content

@gvray/logger


@gvray/logger / redactMiddleware

Function: redactMiddleware() ​

redactMiddleware(patterns): LogMiddleware

Defined in: middleware/redact.ts:19

Middleware that redacts sensitive data from string arguments.

Each string argument is matched against the provided patterns; matches are replaced with [REDACTED]. String patterns use literal substring replacement; RegExp patterns use standard replacement.

Parameters ​

patterns ​

(string | RegExp)[]

Strings (matched literally) and/or regexes to redact.

Returns ​

LogMiddleware

A LogMiddleware instance.

Example ​

ts
logger.use(redactMiddleware(['password', /\d{4}-\d{4}-\d{4}-\d{4}/]));
logger.info('card=1234-5678-9012-3456'); // card=[REDACTED]

Released under the MIT License.