log

package
v0.55.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, args ...any)

Debug logs a message at the debug level using the logger in the context.

See: Logger.Debug

func Error

func Error(ctx context.Context, args ...any)

Error logs a message at the error level using the logger in the context.

See: Logger.Error

func Info

func Info(ctx context.Context, args ...any)

Info logs a message at the info level using the logger in the context.

See: Logger.Info

func IsLevel

func IsLevel(logger Logger, level Level) bool

IsLevel reports whether current logger shows logs for the given log level.

func Panic

func Panic(ctx context.Context, args ...any)

Panic logs a message at the panic level using the logger in the context.

See: Logger.Panic

func Warn

func Warn(ctx context.Context, args ...any)

Warn logs a message at the warn level using the logger in the context.

See: Logger.Warn

func WithField

func WithField(parent context.Context, key string, value any) context.Context

WithField adds a field to the logger in the context.

See: Logger.WithField

func WithFields

func WithFields(parent context.Context, fields Fields) context.Context

WithFields adds fields to the logger in the context.

See: Logger.WithFields

func WithLogger

func WithLogger(parent context.Context, logger Logger) context.Context

WithLogger returns a new context with the provided logger.

See: Logger.WithField

Types

type ErrorWithFields

type ErrorWithFields interface {
	error
	LogFields() Fields
}

type Fields

type Fields = map[string]any

type Level

type Level uint8
const (
	PanicLevel Level = iota
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
)

func ParseLevel

func ParseLevel(lvl string) (Level, error)

ParseLevel takes a string level and returns the Logrus log level constant.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	// Level returns the current logging level.
	Level() Level

	// WithField returns a new logger instance that includes the specified
	// key-value pair.
	WithField(key string, value any) Logger

	// WithFields returns a new logger instance that includes the specified
	// key-value pairs.
	WithFields(fields Fields) Logger

	// WithError associates an error with the logger, returning a new logger
	// instance. The associated error will be included in subsequent log
	// messages.
	WithError(err error) Logger

	// WithAdvice associates a recommended action or advice with the logger,
	// detailing what steps should be taken in response to the event being
	// logged. This can be helpful to guide system administrators or developers
	// on the appropriate course of action when reading the logs.
	//
	// Examples:
	// - "Ignore if happens occasionally"
	// - "This is a known issue; a fix is in progress"
	// - "Report immediately to the development team"
	WithAdvice(advice string) Logger

	// Debug logs detailed system-level diagnostic messages useful during
	// development and troubleshooting. It should contain information that's
	// typically too verbose for regular operation.
	Debug(args ...any)

	// Info logs informational messages that highlight the progress of the
	// application's normal operation, such as startup and significant runtime
	// events. These messages should be concise but informative for system
	// administrators and should not occur at a high rate.
	Info(args ...any)

	// Warn logs potentially harmful situations, unexpected events, or minor
	// issues. This might include things like deprecations or approaching
	// resource limits. These aren't immediate errors but can lead to them if
	// unaddressed.
	Warn(args ...any)

	// Error logs failures that prevent an operation from completing
	// successfully. While the application might continue running, these issues
	// typically require intervention to resolve, either as system
	// administration or code changes.
	Error(args ...any)

	// Panic logs severe errors that might cause the application to crash or be
	// in an unstable state. Logging at this level should be rare and often
	// followed by program termination. These messages should provide enough
	// context to diagnose and rectify catastrophic failures.
	Panic(args ...any)
}

Logger defines an interface for structured logging with varying levels of severity.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext returns the logger from the context. If no logger is found, it returns a null logger.

func Null

func Null() Logger

type LoggerService

type LoggerService interface {
	Logger
	Start(ctx context.Context) error
	Wait() <-chan error
}

LoggerService is a logger that needs to be started to be used.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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