Skip to main content
Home
This release is 2 versions behind 1.0.4 — the latest version of @logtape/redaction. Jump to latest

Built and signed on GitHub Actions

Data redaction for LogTape

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a week ago (1.0.2)
function redactByPattern
redactByPattern(
formatter: TextFormatter,
): TextFormatter

Applies data redaction to a TextFormatter.

Note that there are some built-in redaction patterns:

Examples

Example 1

import { getFileSink } from "@logtape/file";
import { getAnsiColorFormatter } from "@logtape/logtape";
import {
  CREDIT_CARD_NUMBER_PATTERN,
  EMAIL_ADDRESS_PATTERN,
  JWT_PATTERN,
  redactByPattern,
} from "@logtape/redaction";

const formatter = redactByPattern(getAnsiConsoleFormatter(), [
  CREDIT_CARD_NUMBER_PATTERN,
  EMAIL_ADDRESS_PATTERN,
  JWT_PATTERN,
]);
const sink = getFileSink("my-app.log", { formatter });

Parameters

formatter: TextFormatter

The text formatter to apply redaction to.

The redaction patterns to apply.

Return Type

TextFormatter

The redacted text formatter.

redactByPattern(
formatter: ConsoleFormatter,
): ConsoleFormatter

Applies data redaction to a ConsoleFormatter.

Note that there are some built-in redaction patterns:

Examples

Example 1

import { defaultConsoleFormatter, getConsoleSink } from "@logtape/logtape";
import {
  CREDIT_CARD_NUMBER_PATTERN,
  EMAIL_ADDRESS_PATTERN,
  JWT_PATTERN,
  redactByPattern,
} from "@logtape/redaction";

const formatter = redactByPattern(defaultConsoleFormatter, [
  CREDIT_CARD_NUMBER_PATTERN,
  EMAIL_ADDRESS_PATTERN,
  JWT_PATTERN,
]);
const sink = getConsoleSink({ formatter });

Parameters

formatter: ConsoleFormatter

The console formatter to apply redaction to.

The redaction patterns to apply.

Return Type

ConsoleFormatter

The redacted console formatter.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@logtape/redaction

Import symbol

import { redactByPattern } from "@logtape/redaction";
or

Import directly with a jsr specifier

import { redactByPattern } from "jsr:@logtape/redaction";

Add Package

pnpm i jsr:@logtape/redaction
or (using pnpm 10.8 or older)
pnpm dlx jsr add @logtape/redaction

Import symbol

import { redactByPattern } from "@logtape/redaction";

Add Package

yarn add jsr:@logtape/redaction
or (using Yarn 4.8 or older)
yarn dlx jsr add @logtape/redaction

Import symbol

import { redactByPattern } from "@logtape/redaction";

Add Package

vlt install jsr:@logtape/redaction

Import symbol

import { redactByPattern } from "@logtape/redaction";

Add Package

npx jsr add @logtape/redaction

Import symbol

import { redactByPattern } from "@logtape/redaction";

Add Package

bunx jsr add @logtape/redaction

Import symbol

import { redactByPattern } from "@logtape/redaction";