log

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: GPL-3.0, LGPL-3.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LevelTrace slog.Level = -8
	LevelDebug            = slog.LevelDebug
	LevelInfo             = slog.LevelInfo
	LevelWarn             = slog.LevelWarn
	LevelError            = slog.LevelError
	LevelCrit  slog.Level = 12

	// for backward-compatibility
	LvlTrace = LevelTrace
	LvlInfo  = LevelInfo
	LvlDebug = LevelDebug
)

Variables

This section is empty.

Functions

func DiscardHandler added in v0.13.4

func DiscardHandler() slog.Handler

DiscardHandler returns a no-op handler

func FormatLogfmtUint64

func FormatLogfmtUint64(n uint64) string

FormatLogfmtUint64 formats n with thousand separators.

func FormatSlogValue added in v0.13.4

func FormatSlogValue(v slog.Value, tmp []byte) (result []byte)

FormatSlogValue formats a slog.Value for serialization to terminal.

func FromLegacyLevel added in v0.13.4

func FromLegacyLevel(lvl int) slog.Level

convert from old Geth verbosity level constants to levels defined by slog

func JSONHandler added in v0.13.4

func JSONHandler(wr io.Writer) slog.Handler

JSONHandler returns a handler which prints records in JSON format.

func JSONHandlerWithLevel added in v0.13.4

func JSONHandlerWithLevel(wr io.Writer, level slog.Leveler) slog.Handler

func LevelAlignedString added in v0.13.4

func LevelAlignedString(l slog.Level) string

LevelAlignedString returns a 5-character string containing the name of a Lvl.

func LevelString added in v0.13.4

func LevelString(l slog.Level) string

LevelString returns a 5-character string containing the name of a Lvl.

func LogfmtHandler added in v0.13.4

func LogfmtHandler(wr io.Writer) slog.Handler

LogfmtHandler returns a handler which prints records in logfmt format, an easy machine-parseable but human-readable format for key/value pairs.

For more details see: http://godoc.org/github.com/kr/logfmt

func LogfmtHandlerWithLevel added in v0.13.4

func LogfmtHandlerWithLevel(wr io.Writer, level slog.Leveler) slog.Handler

LogfmtHandlerWithLevel returns the same handler as LogfmtHandler but it only outputs records which are less than or equal to the specified verbosity level.

func LvlFromString added in v0.13.4

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

LvlFromString returns the appropriate Lvl from a string name. Useful for parsing command line args and configuration files.

Types

type Logger added in v0.13.4

type Logger interface {
	// With returns a new Logger that has this logger's attributes plus the given attributes
	With(ctx ...interface{}) Logger

	// With returns a new Logger that has this logger's attributes plus the given attributes. Identical to 'With'.
	New(ctx ...interface{}) Logger

	// Log logs a message at the specified level with context key/value pairs
	Log(level slog.Level, msg string, ctx ...interface{})

	// Trace log a message at the trace level with context key/value pairs
	Trace(msg string, ctx ...interface{})

	// Debug logs a message at the debug level with context key/value pairs
	Debug(msg string, ctx ...interface{})

	// Info logs a message at the info level with context key/value pairs
	Info(msg string, ctx ...interface{})

	// Warn logs a message at the warn level with context key/value pairs
	Warn(msg string, ctx ...interface{})

	// Error logs a message at the error level with context key/value pairs
	Error(msg string, ctx ...interface{})

	// Crit logs a message at the crit level with context key/value pairs, and exits
	Crit(msg string, ctx ...interface{})

	// Write logs a message at the specified level
	Write(level slog.Level, msg string, attrs ...any)

	// Enabled reports whether l emits log records at the given context and level.
	Enabled(ctx context.Context, level slog.Level) bool
}

A Logger writes key/value pairs to a Handler

func NewLogger added in v0.13.4

func NewLogger(h slog.Handler) Logger

NewLogger returns a logger with the specified handler set

type TerminalHandler added in v0.13.4

type TerminalHandler struct {

	// Prefix returns a string that is output before each log message.
	Prefix func(r slog.Record) string
	// contains filtered or unexported fields
}

func NewTerminalHandler added in v0.13.4

func NewTerminalHandler(wr io.Writer, useColor bool) *TerminalHandler

NewTerminalHandler returns a handler which formats log records at all levels optimized for human readability on a terminal with color-coded level output and terser human friendly timestamp. This format should only be used for interactive programs or while developing.

[LEVEL] [TIME] MESSAGE key=value key=value ...

Example:

[DBUG] [May 16 20:58:45] remove route ns=haproxy addr=127.0.0.1:50002

func NewTerminalHandlerWithLevel added in v0.13.4

func NewTerminalHandlerWithLevel(wr io.Writer, lvl slog.Leveler, useColor bool) *TerminalHandler

NewTerminalHandlerWithLevel returns the same handler as NewTerminalHandler but only outputs records which are less than or equal to the specified verbosity level.

func (*TerminalHandler) Enabled added in v0.13.4

func (h *TerminalHandler) Enabled(_ context.Context, level slog.Level) bool

func (*TerminalHandler) Handle added in v0.13.4

func (h *TerminalHandler) Handle(_ context.Context, r slog.Record) error

func (*TerminalHandler) ResetFieldPadding added in v0.13.4

func (t *TerminalHandler) ResetFieldPadding()

ResetFieldPadding zeroes the field-padding for all attribute pairs.

func (*TerminalHandler) WithAttrs added in v0.13.4

func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*TerminalHandler) WithGroup added in v0.13.4

func (h *TerminalHandler) WithGroup(name string) slog.Handler

type TerminalStringer

type TerminalStringer interface {
	TerminalString() string
}

TerminalStringer is an analogous interface to the stdlib stringer, allowing own types to have custom shortened serialization formats when printed to the screen.

Jump to

Keyboard shortcuts

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