Documentation
¶
Overview ¶
Package logging sets up the process logger of the tt core.
tt logs through the github.com/tarantool/tt/sdk/log facade, which writes to slog.Default. This package builds the handler behind it and installs it: records below the configured level are dropped, every record has its secrets redacted with the process-wide sdk/log registry and the trailing line breaks of its message trimmed, and what is left is rendered as text for people or as JSON for machines. Logs go to stderr; stdout is left to command results.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoWriter = errors.New("log writer is not set")
ErrNoWriter is returned when Options carries no writer.
var ErrUnknownFormat = errors.New("unknown log format")
ErrUnknownFormat is returned for a log format other than text or json.
Functions ¶
func NewHandler ¶
NewHandler builds the handler chain Options describe without installing it.
The text handler implements sdklog.StatusHandler, so sdklog.Spinner draws through it: on a terminal that can redraw a line the spinner is shown on the writer below the records, anywhere else it is not shown at all. The JSON handler shows no spinner.
Types ¶
type Format ¶
type Format string
Format is a log format. It implements pflag.Value, so it can back a flag directly: an unknown value is refused while the flags are parsed.
type Options ¶
type Options struct {
// Level is the lowest level logged. The zero value is slog.LevelInfo.
Level slog.Level
// Format selects the rendering: FormatText or FormatJSON.
Format Format
// Writer receives the rendered records; tt passes os.Stderr.
Writer io.Writer
// Redactor masks secrets in every record. Nil means the process-wide
// registry, sdklog.Secrets.
Redactor *sdklog.Redactor
// IsTerminal reports whether Writer is a terminal; the text format is
// coloured and shows a spinner status line only on one. Nil means a
// probe of the file descriptor when Writer is an *os.File.
IsTerminal func(io.Writer) bool
// LookupEnv reads the environment for NO_COLOR and TERM. Nil means
// os.LookupEnv.
LookupEnv func(key string) (string, bool)
}
Options configure the process logger.