log

package
v0.0.0-...-1c7db09 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToContext

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

ToContext save logger into context

func WithRequest

func WithRequest(ctx context.Context, req *http.Request) context.Context

WithRequest returns a context which knows the request ID and correlation ID in the given request.

Types

type Logger

type Logger interface {
	// With returns a logger based off the root logger and decorates it with the given context and arguments.
	With(ctx context.Context, args ...zap.Field) Logger

	// Debug uses fmt.Sprint to construct and log a message at DEBUG level
	Debug(msg string, args ...zap.Field)
	// Info uses fmt.Sprint to construct and log a message at INFO level
	Info(msg string, args ...zap.Field)
	// Warn uses fmt.Sprint to construct and log a message at ERROR level
	Warn(msg string, args ...zap.Field)
	// Error uses fmt.Sprint to construct and log a message at ERROR level
	Error(msg string, args ...zap.Field)
}

Logger is a logger that supports log levels, context and structured logging.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext get logger from context or create new logger

func New

func New() Logger

New creates a new logger using the default configuration.

func NewForTest

func NewForTest() (Logger, *observer.ObservedLogs)

NewForTest returns a new logger and the corresponding observed logs which can be used in unit tests to verify log entries.

func NewWithZap

func NewWithZap(l *zap.Logger) Logger

NewWithZap creates a new logger using the preconfigured zap logger.

Jump to

Keyboard shortcuts

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