logger

package
v0.101.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package logger provides logging configuration and helpers to pass a logger instance through the context.

Index

Constants

View Source
const ErrKey = "err"

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) (logger *slog.Logger)

FromContext returns the *slog.Logs previously stored in ctx by NewContext. slog.Default() is returned otherwise.

func FromContextMaybe

func FromContextMaybe(ctx context.Context) (logger *slog.Logger)

FromContextMaybe returns the *slog.Logs previously stored in ctx by NewContext or nil.

func FromRootCommand

func FromRootCommand(cmd *cobra.Command) (logger *slog.Logger)

FromRootCommand returns a logger from the root cobra.Command context or nil.

func NewContext

func NewContext(ctx context.Context, logger *slog.Logger) context.Context

NewContext returns a new Context that carries value logger. Use FromContext to retrieve the value.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config specifies user configurable flag values to create a NewLogger

func NewConfig

func NewConfig() *Config

NewConfig returns a new logging Config struct

func (*Config) FlagSet

func (c *Config) FlagSet() *flag.FlagSet

FlagSet returns the go flag set to configure logging

func (*Config) Format added in v0.100.0

func (c *Config) Format() string

func (*Config) GetLogLevel

func (c *Config) GetLogLevel() slog.Level

GetLogLevel returns a slog.Level configured by the user

A non-zero length DEBUG env var takes precedence over config fields.

func (*Config) Level added in v0.100.0

func (c *Config) Level() string

func (*Config) NewLogger

func (c *Config) NewLogger(w io.Writer) *slog.Logger

NewLogger returns a *slog.Logs configured by c *Config which writes to w

func (*Config) ReplaceAttr

func (c *Config) ReplaceAttr(groups []string, a slog.Attr) slog.Attr

func (*Config) Vet

func (c *Config) Vet() error

Vet validates the config values

Jump to

Keyboard shortcuts

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