Keep secrets and personal data out of what a Go program writes

embargo keeps secrets and personal data out of what a Go program writes: logs, error reports, HTTP access logs and traces. It works inside the application, where the value is written, and the root module has no dependencies outside the standard library. The embargo command masks the output of any program.

Try it #

// next is the handler you already use, such as slog.NewJSONHandler(os.Stdout, nil).
logger := slog.New(embargo.NewSlogHandler(next, embargo.NewScanner()))

logger.Info("login failed", "email", "alice@example.com", "password", "hunter2", "request_id", "req-7f3a")

// Output: {"level":"INFO","msg":"login failed","email":"[REDACTED]","password":"[REDACTED]","request_id":"req-7f3a"}
$ printf '%s\n' 'login failed for alice@example.com from 203.0.113.7' | embargo
login failed for [REDACTED] from [REDACTED]

What it is for #

You need toUse
Keep a known secret, such as an API key, from ever printingSecret
Log the structs, errors and JSON you already haveThe slog handler and MaskJSON, plus adapters for zap, zerolog, logrus, gRPC, OpenTelemetry and Sentry
Catch secrets nobody declared, such as a card number inside an error message39 built-in detectors
Mask a log you already have, or the output of a program you cannot changeThe embargo command
Prove in CI that no secret reaches the outputembargotest

Redaction in a log pipeline can still run after it; embargo stops the leak where it is written. Compare shows what other Go libraries and embargo catch on the same service output, what neither catches, and the speed of each.