Documentation
¶
Overview ¶
Package cmdlog builds the logger of the relay proxy: a slog.Logger writing JSON or logfmt lines to a writer (stderr by default), with the level and the format of the configuration.
Index ¶
Constants ¶
const ( // LevelKey is the key of the level of a record. LevelKey = "level" // TimeKey is the key of the time of a record, in seconds since the epoch. TimeKey = "ts" // CallerKey is the key of the "dir/file.go:line" that logged the record. CallerKey = "caller" // MessageKey is the key of the message of a record. MessageKey = "msg" // ErrorKey is the key of the attribute made by [Err]. ErrorKey = "error" )
Output keys.
const LevelFatal = slog.Level(12)
LevelFatal is the level of the messages logged right before the process exits.
const RedactedValue = "[REDACTED]"
RedactedValue is what a Secret prints instead of its content.
Variables ¶
var ErrUnknownFormat = errors.New("unknown log format")
ErrUnknownFormat is returned for a log format that is neither json nor logfmt.
var ErrUnrecognizedLevel = errors.New("unrecognized level")
ErrUnrecognizedLevel is returned for a log level that is not one of the supported names.
Functions ¶
func Err ¶
Err is the attribute of an error, under the "error" key. A nil error gives an empty attribute, which the handlers skip.
func ParseLevel ¶
ParseLevel converts a configured log level. It accepts what zap accepted (zapcore.Level.UnmarshalText): the names debug, info (also empty), warn (also warning), error, dpanic, panic and fatal, in any letter case. dpanic, panic and fatal are above the error level, as in zap: only the records of the fatal level pass.
func SecretAttr ¶
SecretAttr is a log attribute holding a secret: only its redacted form is logged.
Types ¶
type Format ¶
type Format int32
Format is an output format of the handler.
func ParseFormat ¶
ParseFormat converts a configured log format.
type Logger ¶
type Logger struct {
// Slog is the logger to pass to the code that logs.
Slog *slog.Logger
// contains filtered or unexported fields
}
Logger is the logger of the process, built from the log level and the log format. The handlers of every logger derived from Logger.Slog (With, WithGroup) follow Logger.Update.
func NewDefault ¶
NewDefault builds the logger that is used until the configuration is read: json lines at the info level on stderr.
type Option ¶
type Option func(*options)
Option configures the logger.
func WithWriter ¶
WithWriter sets where the logger writes. The default is stderr. Writes are serialised by the logger, the writer does not need to be safe for concurrent use.
type Secret ¶
type Secret string
Secret is a string that must never reach the logs (API key, token, connection string, ...). Whatever the handler or the formatting verb, it only ever prints RedactedValue.
func (Secret) GoString ¶
GoString implements fmt.GoStringer, so "%#v" never leaks the secret.
func (Secret) MarshalText ¶
MarshalText implements encoding.TextMarshaler, so JSON and YAML encoders never leak the secret.
func (Secret) String ¶
String implements fmt.Stringer, so "%v" and "%s" never leak the secret.