log

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscardHandler

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

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

FormatSlogValue formats a slog.Value for serialization to terminal.

func JSONHandler

func JSONHandler(wr io.Writer) slog.Handler

JSONHandler returns a handler which prints records in JSON format.

func JSONHandlerWithLevel

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

JSONHandlerWithLevel returns a handler which prints records in JSON format that are less than or equal to the specified verbosity level.

func LogfmtHandler

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

func LogfmtHandlerWithLevel(wr io.Writer, level slog.Level) 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.

Types

type TerminalHandler

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

func NewTerminalHandler

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

func NewTerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, 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

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

func (*TerminalHandler) Handle

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

func (*TerminalHandler) ResetFieldPadding

func (t *TerminalHandler) ResetFieldPadding()

ResetFieldPadding zeroes the field-padding for all attribute pairs.

func (*TerminalHandler) WithAttrs

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

func (*TerminalHandler) WithGroup

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