logger

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 1 Imported by: 2 modules, 125 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logger defines the structured logging interface and a global default logger that components use when no explicit logger is configured.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefault

func SetDefault(logger Logger)

SetDefault sets the global default Logger.

Types

type LogFormat

type LogFormat string

LogFormat is the log output format type.

const (
	// TextFormat produces human-readable log output.
	TextFormat LogFormat = "text"
	// JSONFormat produces structured JSON log output.
	JSONFormat LogFormat = "json"
)

type LogLevel

type LogLevel string

LogLevel is the severity level of a log entry.

const (
	// TraceLevel has more verbose messages than DebugLevel.
	TraceLevel LogLevel = "trace"
	// DebugLevel is for verbose diagnostic messages.
	DebugLevel LogLevel = "debug"
	// InfoLevel is the default log level for informational messages.
	InfoLevel LogLevel = "info"
	// WarnLevel is for messages about potential issues.
	WarnLevel LogLevel = "warn"
	// ErrorLevel is for error messages indicating a failure.
	ErrorLevel LogLevel = "error"
	// FatalLevel is for fatal errors. The program typically exits after logging.
	FatalLevel LogLevel = "fatal"
)

type Logger

type Logger interface {
	// WithFields returns a new Logger with the given fields attached to
	// every subsequent log entry.
	WithFields(map[string]any) Logger
	Trace(args ...any)
	Tracef(format string, args ...any)
	Debug(args ...any)
	Debugf(format string, args ...any)
	Info(args ...any)
	Infof(format string, args ...any)
	Warn(args ...any)
	Warnf(format string, args ...any)
	Error(args ...any)
	Errorf(format string, args ...any)
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	// GetLevel returns the current log level.
	GetLevel() LogLevel
	// IsLevelEnabled reports whether messages at the given level are logged.
	IsLevelEnabled(level LogLevel) bool
}

Logger is the structured logging interface. Implementations may write to files, stdout, sockets, or external log services.

func Default

func Default() Logger

Default returns the global default Logger. It may return nil if no default has been set.

func LoggerGroup

func LoggerGroup(loggers ...Logger) Logger

LoggerGroup creates a Logger that broadcasts all log calls to the given set of loggers. This is useful for emitting logs to multiple destinations simultaneously (e.g. both a file and stdout).

Jump to

Keyboard shortcuts

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