redact

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package redact removes secrets from log attributes via a key denylist, value-pattern detection, and an explicit Secret marker type.

Index

Constants

View Source
const DefaultReplacement = "***"

DefaultReplacement is the string substituted for redacted values.

Variables

This section is empty.

Functions

func DefaultAllowKeys

func DefaultAllowKeys() []string

DefaultAllowKeys returns the built-in trusted correlation key names whose values bypass pattern/entropy scanning. The denylist still wins.

func DefaultDenyKeys

func DefaultDenyKeys() []string

DefaultDenyKeys returns the built-in sensitive key names.

func Secret

func Secret(v any) slog.LogValuer

Secret marks a value as always-redacted regardless of its key. It implements slog.LogValuer so the value never reaches a handler in clear text.

Types

type Option

type Option func(*Redactor)

Option configures a Redactor.

func WithDenyKeys

func WithDenyKeys(keys ...string) Option

WithDenyKeys replaces the default deny set with the given keys. If combined with WithExtraDenyKeys, list WithDenyKeys first; it replaces the entire set.

func WithExtraAllowKeys

func WithExtraAllowKeys(keys ...string) Option

WithExtraAllowKeys adds keys to the allow set, bypassing value-pattern scanning. The denylist still takes precedence: a key in both deny and allow is redacted.

func WithExtraDenyKeys

func WithExtraDenyKeys(keys ...string) Option

WithExtraDenyKeys adds keys to the existing deny set. Apply after WithDenyKeys, which would otherwise discard these additions.

func WithReplacement

func WithReplacement(s string) Option

WithReplacement sets the substitute string for redacted values.

func WithoutPatternScan

func WithoutPatternScan() Option

WithoutPatternScan disables value-pattern detection (key + Secret still apply).

type Redactor

type Redactor struct {
	// contains filtered or unexported fields
}

Redactor redacts slog attributes. It is safe for concurrent use.

func New

func New(opts ...Option) *Redactor

New builds a Redactor with the default deny set and pattern scan enabled.

func (*Redactor) Attr

func (r *Redactor) Attr(a slog.Attr) slog.Attr

Attr returns a redacted copy of a.

Source Files

  • redactor.go
  • secret.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL