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 ¶
- func ColorEnabled(w io.Writer, mode ColorMode) bool
- func FromContext(ctx context.Context, opts ...Option) *slog.Logger
- func Multi(loggers ...*slog.Logger) *slog.Logger
- func New(opts ...Option) *slog.Logger
- func NewNoop() *slog.Logger
- func ParseLevel(value string) (slog.Level, error)
- func WithSettings(ctx context.Context, settings Settings) context.Context
- type ColorMode
- type Format
- type Option
- func WithColor(color ColorMode) Option
- func WithDebug(debug bool) Optiondeprecated
- func WithFormat(format Format) Option
- func WithJSON(json bool) Optiondeprecated
- func WithLevel(level slog.Leveler) Option
- func WithPretty(pretty bool) Optiondeprecated
- func WithSource(source bool) Option
- func WithWriter(w io.Writer) Option
- func WithWriters(w ...io.Writer) Option
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorEnabled ¶ added in v0.30.0
ColorEnabled reports whether color should be emitted to w under mode.
func FromContext ¶ added in v0.30.0
FromContext creates a logger using settings stored in ctx.
func Multi ¶
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 ¶
New creates a *slog.Logger configured by the given options.
Defaults: Info level, auto format and color, writes to os.Stderr.
func ParseLevel ¶ added in v0.30.0
ParseLevel parses one of the supported minimum log levels.
Types ¶
type ColorMode ¶ added in v0.30.0
type ColorMode string
ColorMode controls whether console logs contain ANSI color sequences.
func ParseColorMode ¶ added in v0.30.0
ParseColorMode parses a supported console color policy.
type Format ¶ added in v0.30.0
type Format string
Format controls how log records are rendered.
func ParseFormat ¶ added in v0.30.0
ParseFormat parses a supported log output format.
type Option ¶
type Option func(*config)
Option configures a Logger created with New.
func WithFormat ¶ added in v0.30.0
WithFormat sets the log record format.
func WithPretty
deprecated
func WithSource ¶
WithSource includes source file:line in log output.
func WithWriter ¶
WithWriter overrides the output writer. Defaults to os.Stderr.
func WithWriters ¶
WithWriters sets multiple output writers with per-destination handlers.
type Settings ¶ added in v0.30.0
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
ParseSettings validates and resolves user-facing logging values.
func SettingsFromContext ¶ added in v0.30.0
SettingsFromContext returns resolved settings or the package defaults.
func (Settings) New ¶ added in v0.30.0
New creates a logger from these settings plus any sink-specific options.
func (Settings) WithDefaultFormat ¶ added in v0.30.0
WithDefaultFormat replaces auto with a sink-specific default format.