logging

package
v1.28.10 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 3 Imported by: 1,138 modules, 1,151 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Classification

type Classification string

Classification is the type of the log entry's classification name.

const (
	Warn  Classification = "WARN"
	Debug Classification = "DEBUG"
)

Set of standard classifications that can be used by clients and middleware

type ContextLogger

type ContextLogger interface {
	WithContext(context.Context) Logger
}

ContextLogger is an optional interface a Logger implementation may expose that provides the ability to create context aware log entries.

type Logger

type Logger interface {
	// Logf is expected to support the standard fmt package "verbs".
	Logf(classification Classification, format string, v ...interface{})
}

Logger is an interface for logging entries at certain classifications.

func WithContext

func WithContext(ctx context.Context, logger Logger) Logger

WithContext will pass the provided context to logger if it implements the ContextLogger interface and return the resulting logger. Otherwise the logger will be returned as is. As a special case if a nil logger is provided, a Nop logger will be returned to the caller.

type LoggerFunc added in v1.1.0

type LoggerFunc func(classification Classification, format string, v ...interface{})

LoggerFunc is a wrapper around a function to satisfy the Logger interface.

func (LoggerFunc) Logf added in v1.1.0

func (f LoggerFunc) Logf(classification Classification, format string, v ...interface{})

Logf delegates the logging request to the wrapped function.

type Nop

type Nop struct{}

Nop is a Logger implementation that simply does not perform any logging.

func (Nop) Logf

func (n Nop) Logf(Classification, string, ...interface{})

Logf simply returns without performing any action

type StandardLogger

type StandardLogger struct {
	Logger *log.Logger
}

StandardLogger is a Logger implementation that wraps the standard library logger, and delegates logging to it's Printf method.

func NewStandardLogger

func NewStandardLogger(writer io.Writer) *StandardLogger

NewStandardLogger returns a new StandardLogger

func (StandardLogger) Logf

func (s StandardLogger) Logf(classification Classification, format string, v ...interface{})

Logf logs the given classification and message to the underlying logger.

Jump to

Keyboard shortcuts

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