stdlog

package module
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const Discard noop = "noop"

Variables

This section is empty.

Functions

This section is empty.

Types

type FatalBehavior added in v0.0.19

type FatalBehavior uint8

FatalBehavior determines how Logger behaves when Logger.Fatal or Logger.FatalError is called. See Logger.SetFatalBehavior

const (
	// FatalExits makes Logger invoke os.Exit with status 1 after printing a
	// message with a Fatal log level. This is the default mode.
	FatalExits FatalBehavior = iota

	// FatalPanics makes Logger emit a panic with the same message as provided
	// to the logger method. This does not invoke os.Exit.
	FatalPanics
)

type Level

type Level int
const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarning
	LevelError
	LevelFatal
)

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	// Named returns a new logger with its previous name followed by a dot,
	// followed by the provided name.
	Named(name string) Logger

	// SetLevel sets the logger level.
	SetLevel(level Level)

	// Leveled returns a copy of the current logger with a different level.
	Leveled(level Level) Logger

	// WithFields returns a copy of the current logger with extra provided
	// fields that will be present in every emitted log message.
	WithFields(keysAndValues ...any) Logger

	// Skipping returns a copy of the current logger that will skip a given
	// number of call stacks.
	Skipping(count uint) Logger

	// SetFatalBehavior defines how Logger behaves when Fatal or FatalError is
	// called. By default, Logger uses FatalExits, which means that any call to
	// a fatal logger level calls os.Exit with status 1. The other option,
	// FatalPanics, panics after printing the log message to the configured
	// output, allowing deferred functions to be executed.
	SetFatalBehavior(behavior FatalBehavior)

	Debug(msg string, keysAndValues ...any)
	Info(msg string, keysAndValues ...any)
	Warning(msg string, keysAndValues ...any)
	Error(err error, msg string, keysAndValues ...any)
	Fatal(msg string, keysAndValues ...any)
	FatalError(err error, msg string, keysAndValues ...any)
}

func NewStd added in v0.0.8

func NewStd(writer io.Writer) Logger

func NewStdJSON added in v0.0.8

func NewStdJSON(writer io.Writer) Logger

Jump to

Keyboard shortcuts

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