log

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelFlagName  = "log.level"
	FormatFlagName = "log.format"
	ColorFlagName  = "log.color"
)

Variables

This section is empty.

Functions

func AppOut

func AppOut(ctx *cli.Context) io.Writer

AppOut returns an io.Writer to write app output to, like logs. This falls back to os.Stdout if the ctx, ctx.App or ctx.App.Writer are nil.

func CLIFlags

func CLIFlags(envPrefix string) []cli.Flag

func CLIFlagsWithCategory added in v1.4.0

func CLIFlagsWithCategory(envPrefix string, category string) []cli.Flag

CLIFlagsWithCategory creates flag definitions for the logging utils. Warning: flags are not safe to reuse due to an upstream urfave default-value mutation bug in GenericFlag. Use cliapp.ProtectFlags(flags) to create a copy before passing it into an App if the app runs more than once.

func FormatHandler added in v1.4.0

func FormatHandler(ft FormatType, color bool) func(io.Writer) slog.Handler

FormatHandler returns the correct slog handler factory for the provided format.

func LevelFromString added in v1.4.0

func LevelFromString(lvlString string) (slog.Level, error)

LevelFromString returns the appropriate Level from a string name. Useful for parsing command line args and configuration files. It also converts strings to lowercase. If the string is unknown, LevelDebug is returned as a default, together with a non-nil error.

func NewLogHandler

func NewLogHandler(wr io.Writer, cfg CLIConfig) slog.Handler

NewLogHandler creates a new configured handler, compatible as LvlSetter for log-level changes during runtime.

func NewLogger

func NewLogger(wr io.Writer, cfg CLIConfig) log.Logger

NewLogger creates a new configured logger. The log handler of the logger is a LvlSetter, i.e. the log level can be changed as needed.

func NewLoggingMiddleware

func NewLoggingMiddleware(lgr log.Logger, next http.Handler) http.Handler

func SetGlobalLogHandler

func SetGlobalLogHandler(h slog.Handler)

SetGlobalLogHandler sets the log handles as the handler of the global default logger. The usage of this logger is strongly discouraged, as it does makes it difficult to distinguish different services in the same process, e.g. during tests. Geth and other components may use the global logger however, and it is thus recommended to set the global log handler to catch these logs.

func SetupDefaults

func SetupDefaults()

Types

type CLIConfig

type CLIConfig struct {
	Level  slog.Level
	Color  bool
	Format FormatType
}

func DefaultCLIConfig

func DefaultCLIConfig() CLIConfig

DefaultCLIConfig creates a default log configuration. Color defaults to true if terminal is detected.

func ReadCLIConfig

func ReadCLIConfig(ctx *cli.Context) CLIConfig

type DynamicLogHandler

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

DynamicLogHandler allow runtime-configuration of the log handler.

func NewDynamicLogHandler

func NewDynamicLogHandler(lvl slog.Level, h slog.Handler) *DynamicLogHandler

func (*DynamicLogHandler) Enabled added in v1.4.0

func (d *DynamicLogHandler) Enabled(ctx context.Context, lvl slog.Level) bool

func (*DynamicLogHandler) Handle added in v1.4.0

func (d *DynamicLogHandler) Handle(ctx context.Context, r slog.Record) error

func (*DynamicLogHandler) SetLogLevel

func (d *DynamicLogHandler) SetLogLevel(lvl slog.Level)

func (*DynamicLogHandler) WithAttrs added in v1.4.0

func (d *DynamicLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*DynamicLogHandler) WithGroup added in v1.4.0

func (d *DynamicLogHandler) WithGroup(name string) slog.Handler

type FormatFlagValue

type FormatFlagValue FormatType

FormatFlagValue is a value type for cli.GenericFlag to parse and validate log-formatting-type values

func NewFormatFlagValue

func NewFormatFlagValue(fmtType FormatType) *FormatFlagValue

func (*FormatFlagValue) Clone

func (fv *FormatFlagValue) Clone() any

func (FormatFlagValue) FormatType

func (fv FormatFlagValue) FormatType() FormatType

func (*FormatFlagValue) Set

func (fv *FormatFlagValue) Set(value string) error

func (FormatFlagValue) String

func (fv FormatFlagValue) String() string

type FormatType

type FormatType string

FormatType defines a type of log format. Supported formats: 'text', 'terminal', 'logfmt', 'json'

const (
	FormatText     FormatType = "text"
	FormatTerminal FormatType = "terminal"
	FormatLogFmt   FormatType = "logfmt"
	FormatJSON     FormatType = "json"
)

func (FormatType) String

func (ft FormatType) String() string

type LevelFlagValue added in v1.4.0

type LevelFlagValue slog.Level

LevelFlagValue is a value type for cli.GenericFlag to parse and validate log-level values. Log level: trace, debug, info, warn, error, crit. Capitals are accepted too.

func NewLevelFlagValue added in v1.4.0

func NewLevelFlagValue(lvl slog.Level) *LevelFlagValue

func (*LevelFlagValue) Clone added in v1.4.0

func (fv *LevelFlagValue) Clone() any

func (LevelFlagValue) Level added in v1.4.0

func (fv LevelFlagValue) Level() slog.Level

func (*LevelFlagValue) Set added in v1.4.0

func (fv *LevelFlagValue) Set(value string) error

func (LevelFlagValue) String added in v1.4.0

func (fv LevelFlagValue) String() string

type LvlSetter

type LvlSetter interface {
	SetLogLevel(lvl slog.Level)
}

type Writer

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

func NewWriter

func NewWriter(l log.Logger, lvl slog.Level) *Writer

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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