Help us shape the future of Go! Take the 2026 Go Developer Survey

logredact

package
v0.2.54 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package logredact removes credentials from log output. Handler wraps the final slog handler, so every record is scrubbed whichever call site wrote it: a URL with ?X-Plex-Token=…, an error that quotes a request, a header dump or an attribute named "password". Call-site redaction stays useful (it keeps the shape of a value readable); this is the backstop.

It recognises credentials by name (query parameters, JSON keys, header names and attribute keys, compared case-insensitively ignoring '-' and '_' and after URL-decoding, so %58-Plex-Token is X-Plex-Token), by position (user:password@ in URLs, Bearer/Basic credentials) and by the prefixes of Ether's own credentials. Anything else passes through unchanged.

Index

Constants

View Source
const Mask = "[redacted]"

Mask replaces a removed credential.

Variables

This section is empty.

Functions

func Attr

func Attr(a slog.Attr) slog.Attr

Attr scrubs one attribute.

func Handler

func Handler(next slog.Handler) slog.Handler

Handler returns a slog.Handler that scrubs every record before next sees it: the message, attribute values (inside groups too) and attributes added with WithAttrs. Attributes whose key names a credential lose their value entirely.

func Sensitive

func Sensitive(name string) bool

Sensitive reports whether a parameter, header, JSON key or attribute key names a credential. Percent-encoded names are decoded first.

func String

func String(s string) string

String returns s with credentials replaced by Mask.

Types

This section is empty.

Jump to

Keyboard shortcuts

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