logger

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package logger provides opinionated logging capabilities for the tapes system.

It builds on Go's log/slog, with terminal-aware console output and structured JSON for services. All public constructors return *slog.Logger directly — no custom interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorEnabled added in v0.30.0

func ColorEnabled(w io.Writer, mode ColorMode) bool

ColorEnabled reports whether color should be emitted to w under mode.

func FromContext added in v0.30.0

func FromContext(ctx context.Context, opts ...Option) *slog.Logger

FromContext creates a logger using settings stored in ctx.

func Multi

func Multi(loggers ...*slog.Logger) *slog.Logger

Multi creates a *slog.Logger that dispatches every record to all provided loggers' underlying handlers. Each logger's handler is extracted via (*slog.Logger).Handler().

func New

func New(opts ...Option) *slog.Logger

New creates a *slog.Logger configured by the given options.

Defaults: Info level, auto format and color, writes to os.Stderr.

func NewNoop

func NewNoop() *slog.Logger

NewNoop returns a *slog.Logger that discards all output. Useful for tests.

func ParseLevel added in v0.30.0

func ParseLevel(value string) (slog.Level, error)

ParseLevel parses one of the supported minimum log levels.

func WithSettings added in v0.30.0

func WithSettings(ctx context.Context, settings Settings) context.Context

WithSettings stores resolved logging settings in a context.

Types

type ColorMode added in v0.30.0

type ColorMode string

ColorMode controls whether console logs contain ANSI color sequences.

const (
	ColorAuto   ColorMode = "auto"
	ColorAlways ColorMode = "always"
	ColorNever  ColorMode = "never"
)

func ParseColorMode added in v0.30.0

func ParseColorMode(value string) (ColorMode, error)

ParseColorMode parses a supported console color policy.

type Format added in v0.30.0

type Format string

Format controls how log records are rendered.

const (
	FormatAuto    Format = "auto"
	FormatConsole Format = "console"
	FormatText    Format = "text"
	FormatJSON    Format = "json"
)

func ParseFormat added in v0.30.0

func ParseFormat(value string) (Format, error)

ParseFormat parses a supported log output format.

type Option

type Option func(*config)

Option configures a Logger created with New.

func WithColor added in v0.30.0

func WithColor(color ColorMode) Option

WithColor sets the console color policy.

func WithDebug deprecated

func WithDebug(debug bool) Option

WithDebug sets the log level to Debug when true, Info otherwise.

Deprecated: use WithLevel.

func WithFormat added in v0.30.0

func WithFormat(format Format) Option

WithFormat sets the log record format.

func WithJSON deprecated

func WithJSON(json bool) Option

WithJSON selects JSON output when true and native text when false.

Deprecated: use WithFormat.

func WithLevel added in v0.30.0

func WithLevel(level slog.Leveler) Option

WithLevel sets the minimum enabled log level.

func WithPretty deprecated

func WithPretty(pretty bool) Option

WithPretty selects tint console output when true and native text when false.

Deprecated: use WithFormat.

func WithSource

func WithSource(source bool) Option

WithSource includes source file:line in log output.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter overrides the output writer. Defaults to os.Stderr.

func WithWriters

func WithWriters(w ...io.Writer) Option

WithWriters sets multiple output writers with per-destination handlers.

type Settings added in v0.30.0

type Settings struct {
	Level  slog.Level
	Format Format
	Color  ColorMode
}

Settings are the independently resolved logging concerns shared by a command.

func DefaultSettings added in v0.30.0

func DefaultSettings() Settings

DefaultSettings returns the default logging settings.

func ParseSettings added in v0.30.0

func ParseSettings(level, format, color string) (Settings, error)

ParseSettings validates and resolves user-facing logging values.

func SettingsFromContext added in v0.30.0

func SettingsFromContext(ctx context.Context) Settings

SettingsFromContext returns resolved settings or the package defaults.

func (Settings) New added in v0.30.0

func (s Settings) New(opts ...Option) *slog.Logger

New creates a logger from these settings plus any sink-specific options.

func (Settings) WithDefaultFormat added in v0.30.0

func (s Settings) WithDefaultFormat(format Format) Settings

WithDefaultFormat replaces auto with a sink-specific default format.

Jump to

Keyboard shortcuts

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