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

logging

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logging builds the server's one logger: slog, JSON, to stdout, with a redaction layer wrapped around it.

The redaction layer is the point of the package. A secret reaches a log line by accident, never on purpose — a connection string inside a pgx error, an Authorization header swept up by a request dump, an API key logged while someone was debugging at two in the morning. So the handler treats redaction as its job rather than the caller's: it rewrites attribute values whose key names a secret, and it scrubs message and string values for the shapes a secret has. A caller cannot opt out, and forgetting to think about it is the safe default.

What it cannot do is read minds. A password logged under the key "detail" with no recognisable shape goes through. The rule for callers stays: log the name of a thing, not the thing.

Index

Constants

View Source
const Redacted = "[redacted]"

Redacted replaces every value this package removes. It is a fixed string, so a log search for it finds every place a secret was on its way out.

Variables

This section is empty.

Functions

func Discard

func Discard() *slog.Logger

Discard is a logger that writes nothing. Tests that do not assert on log output use it so a test run stays readable.

func New

func New(opts Options) *slog.Logger

New builds the server's logger. Every line is JSON on one line, which is what a log shipper wants and what `jq` reads, and every line has passed through the redactor.

func Scrub

func Scrub(s string) string

Scrub removes the secrets it can recognise from free text: the password in a connection string, in either spelling, and a bearer credential in prose. The rest of the string survives, because a log line that says which host was unreachable is worth keeping.

func Sensitive

func Sensitive(key string) bool

Sensitive reports whether an attribute key names something that must never be logged. It is exported because the admin panel's "copy diagnostics" button needs the same rule.

Types

type Options

type Options struct {
	// Level is the minimum level that reaches the output. The zero value is
	// [slog.LevelInfo].
	Level slog.Level
	// Output is where lines are written. nil means os.Stdout.
	Output io.Writer
	// AddSource attaches the file and line of the call site. Off by default:
	// it costs a stack walk per line.
	AddSource bool
}

Options configures New. The zero value is valid: info level to stdout.

Jump to

Keyboard shortcuts

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