log

package
v1.5.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 13 Imported by: 89

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func AppOut added in v1.2.0

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

CLIFlags 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 NewLogHandler added in v1.2.0

func NewLogHandler(wr io.Writer, cfg CLIConfig) log.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 added in v1.2.0

func SetGlobalLogHandler(h log.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  log.Lvl
	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 added in v1.2.0

type DynamicLogHandler struct {
	log.Handler // embedded, to expose any extra methods the underlying handler might provide
	// contains filtered or unexported fields
}

DynamicLogHandler allow runtime-configuration of the log handler.

func NewDynamicLogHandler added in v1.2.0

func NewDynamicLogHandler(lvl log.Lvl, h log.Handler) *DynamicLogHandler

func (*DynamicLogHandler) Log added in v1.2.0

func (d *DynamicLogHandler) Log(r *log.Record) error

func (*DynamicLogHandler) SetLogLevel added in v1.2.0

func (d *DynamicLogHandler) SetLogLevel(lvl log.Lvl)

type FormatFlagValue added in v1.2.0

type FormatFlagValue FormatType

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

func NewFormatFlagValue added in v1.2.0

func NewFormatFlagValue(fmtType FormatType) *FormatFlagValue

func (*FormatFlagValue) Clone added in v1.2.0

func (fv *FormatFlagValue) Clone() any

func (FormatFlagValue) FormatType added in v1.2.0

func (fv FormatFlagValue) FormatType() FormatType

func (*FormatFlagValue) Set added in v1.2.0

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

func (FormatFlagValue) String added in v1.2.0

func (fv FormatFlagValue) String() string

type FormatType added in v1.2.0

type FormatType string

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

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

func (FormatType) Formatter added in v1.2.0

func (ft FormatType) Formatter(color bool) log.Format

Formatter turns a format type and color into a structured Format object

func (FormatType) String added in v1.2.0

func (ft FormatType) String() string

type LvlFlagValue added in v1.2.0

type LvlFlagValue log.Lvl

LvlFlagValue 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 NewLvlFlagValue added in v1.2.0

func NewLvlFlagValue(lvl log.Lvl) *LvlFlagValue

func (*LvlFlagValue) Clone added in v1.2.0

func (fv *LvlFlagValue) Clone() any

func (LvlFlagValue) LogLvl added in v1.2.0

func (fv LvlFlagValue) LogLvl() log.Lvl

func (*LvlFlagValue) Set added in v1.2.0

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

func (LvlFlagValue) String added in v1.2.0

func (fv LvlFlagValue) String() string

type LvlSetter added in v1.2.0

type LvlSetter interface {
	SetLogLevel(lvl log.Lvl)
}

type Writer added in v1.1.4

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

func NewWriter added in v1.1.4

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

func (*Writer) Close added in v1.1.4

func (w *Writer) Close() error

func (*Writer) Write added in v1.1.4

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