/** * Redaction * * Turns a `logger.redact` list into the pino options that enforce it. * * Two kinds of entry, enforced two ways: * * - **A key** (`password`, `sub`, `x-api-key` — no `.`, `[` or `*`) means "never print this key, * wherever it is". It is matched case-insensitively (`Authorization` and `authorization`) at any * depth, inside plain objects, arrays and `Error`s, and in `child()` bindings. pino's own * `redact` cannot say this: its paths are exact, there is no `**`, and expanding a key into * `*.k`, `*.*.k`, ... cost ~40 µs a line for five keys — every wildcard level clones the object * again. So keys are handled by one copy-on-write pass in `formatters.log` and * `formatters.bindings` instead: the caller's object is never mutated, and a line without a * match is not copied at all. * - **A path** (`req.headers.authorization`, `items[*].token`) goes to pino's `redact` exactly as * written, and is case-sensitive. * * Neither touches the message string: `logger.info(\`user ${sub}\`)` prints the sub whatever this * list says. * * @example * ```yaml * logger: * redact: * - password # [Redacted], any depth, any case * - req.headers.authorization # exactly this path * - paths: [sub, uid] * hash: { algorithm: sha512, length: 16 } # joinable, not readable * ``` */ import type pino from 'pino'; import type { RedactEntryConfig } from '../config/types.js'; /** Default replacement for a redacted value. */ export declare const DEFAULT_CENSOR = "[Redacted]"; /** How deep the key pass descends before it gives up. Deeper than any sane log object. */ export declare const MAX_KEY_DEPTH = 16; /** What {@link buildRedaction} produces: pino options, plus the pass `child()` needs. */ export interface Redaction { /** `formatters` for key entries (the merged object and the root's `base`), `redact` for paths. */ options: Pick; /** * The key pass for `child()` and `setBindings()` bindings, when there are key entries. pino * applies `formatters.bindings` to the root's `base` only and deliberately resets it for every * child, so {@link applyRedaction} wraps those two methods instead. */ redactBindings?: (bindings: T) => T; } /** * Builds what enforces a `logger.redact` list. An empty list yields no options at all. * * @throws Error on a key or path claimed by two entries with different censors, or a * wildcard-final path (`user.*`) with a custom censor — pino hands a path censor only the * final key, so neither could be told apart */ export declare function buildRedaction(entries: readonly RedactEntryConfig[]): Redaction; /** * Installs the bindings half of a {@link Redaction} on a logger: its `child()` and * `setBindings()` redact their bindings first. Children are created with * `Object.create(parent)`, so they inherit the wrapped methods at every depth. */ export declare function applyRedaction(logger: pino.Logger, redaction: Redaction): pino.Logger; //# sourceMappingURL=redact.d.ts.map