Documentation
¶
Overview ¶
Package logging builds the structured logger every command writes with: log/slog lines in JSON, personal data masked, the request identifier of the context added (ADR 0002).
A value with both a Redacted and a String method, such as domain.Email, domain.Phone or domain.IBAN, is never written as such: the logger writes an object holding its Redacted form and a keyed pseudonym of its String form, {"redacted":"***@exemple.fr","hmac":"…"}. The pseudonym is the first 16 bytes of HMAC-SHA256 under a secret key, in hex: the same value gets the same pseudonym, so lines about it can be grouped, but it cannot be recovered nor guessed by hashing candidates without the key.
Masking relies on the value reaching the logger whole: logging email.String() writes the address. Log the value object itself.
Index ¶
Constants ¶
const MinKeyBytes = 32
MinKeyBytes is the shortest HMAC key New accepts: 32 bytes, the output size of SHA-256, which RFC 2104 (section 3) gives as the minimum recommended key length.
const RequestIDKey = "request_id"
RequestIDKey is the key of the request identifier in a log line.
Variables ¶
var ErrInvalidConfig = errors.New("invalid logging config")
ErrInvalidConfig means New was given a Config it cannot use.
Functions ¶
func New ¶
New returns a logger writing one JSON object per line to w, with personal data masked and the request identifier of the context added.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package loggingtest builds redacting loggers for tests, writing to a buffer the test reads back.
|
Package loggingtest builds redacting loggers for tests, writing to a buffer the test reads back. |