logger

package
v0.4.19 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxGetFields

func CtxGetFields(ctx context.Context) (fields []zap.Field)

func CtxWithFields

func CtxWithFields(ctx context.Context, fields ...zap.Field) context.Context

func Default

func Default() *zap.Logger

func NewNamedSugared

func NewNamedSugared(name string) *zap.SugaredLogger

func SetDefault

func SetDefault(l *zap.Logger)

SetDefault replaces the default logger you need to call SetNamedLevels after in case you have named loggers, otherwise they will use the old logger

func SetNamedLevels

func SetNamedLevels(nls []NamedLevel)

SetNamedLevels sets the namedLevels for named loggers it also supports glob patterns for names, like "app*" can be racy in case there are existing named loggers so consider to call only once at the beginning

func WithCtx

func WithCtx(ctx context.Context, l *zap.Logger) *zap.Logger

Types

type Config

type Config struct {
	Production     bool         `yaml:"production"`
	DefaultLevel   string       `yaml:"defaultLevel"`
	Levels         []NamedLevel `yaml:"levels"` // first match will be used
	AddOutputPaths []string     `yaml:"outputPaths"`
	DisableStdErr  bool         `yaml:"disableStdErr"`
	Format         LogFormat    `yaml:"format"`
	ZapConfig      *zap.Config  `yaml:"-"` // optional, if set it will be used instead of other config options
}

func (Config) ApplyGlobal

func (l Config) ApplyGlobal()

type CtxLogger

type CtxLogger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func NewNamed

func NewNamed(name string, fields ...zap.Field) CtxLogger

func (CtxLogger) DebugCtx

func (cl CtxLogger) DebugCtx(ctx context.Context, msg string, fields ...zap.Field)

func (CtxLogger) ErrorCtx

func (cl CtxLogger) ErrorCtx(ctx context.Context, msg string, fields ...zap.Field)

func (CtxLogger) InfoCtx

func (cl CtxLogger) InfoCtx(ctx context.Context, msg string, fields ...zap.Field)

func (CtxLogger) Sugar

func (cl CtxLogger) Sugar() *zap.SugaredLogger

func (CtxLogger) WarnCtx

func (cl CtxLogger) WarnCtx(ctx context.Context, msg string, fields ...zap.Field)

func (CtxLogger) With

func (cl CtxLogger) With(fields ...zap.Field) CtxLogger

type LogFormat

type LogFormat int
const (
	ColorizedOutput LogFormat = iota
	PlaintextOutput
	JSONOutput
)

type NamedLevel

type NamedLevel struct {
	Name  string `yaml:"name"`
	Level string `yaml:"level"`
}

func LevelsFromStr

func LevelsFromStr(s string) (levels []NamedLevel)

LevelsFromStr parses a string of the form "name1=DEBUG;prefix*=WARN;*=ERROR" into a slice of NamedLevel it may be useful to parse the log level from the OS env var

Jump to

Keyboard shortcuts

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