logging

package
v3.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: BSD-2-Clause Imports: 15 Imported by: 0

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

View Source
var ErrNoWriter = errors.New("log writer is not set")

ErrNoWriter is returned when Options carries no writer.

View Source
var ErrUnknownFormat = errors.New("unknown log format")

ErrUnknownFormat is returned for a log format other than text or json.

Functions

func NewHandler

func NewHandler(opts Options) (slog.Handler, error)

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.

func Setup

func Setup(opts Options) error

Setup builds the handler chain Options describe and makes it the handler of slog.Default. slog.SetDefault also routes the standard library's log package through it.

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.

const (
	// FormatText renders a record as one human-readable line.
	FormatText Format = "text"
	// FormatJSON renders a record as one JSON object per line, as
	// slog.JSONHandler does.
	FormatJSON Format = "json"
)

func (*Format) Set

func (f *Format) Set(value string) error

Set parses value as a format name.

func (*Format) String

func (f *Format) String() string

String returns the format name.

func (*Format) Type

func (*Format) Type() string

Type names the flag value type in the help output.

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.

Jump to

Keyboard shortcuts

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