logging

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: AGPL-3.0 Imports: 4 Imported by: ? modules, 0 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

View Source
const (
	// LoggerNameKey is a key we can use to denote logger names across implementations.
	LoggerNameKey = "service_name"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level *level

Level is a simple string alias for dependency injection's sake.

var (
	// InfoLevel describes a info-level log.
	InfoLevel Level = new(level("info"))
	// DebugLevel describes a debug-level log.
	DebugLevel Level = new(level("debug"))
	// ErrorLevel describes a error-level log.
	ErrorLevel Level = new(level("error"))
	// WarnLevel describes a warn-level log.
	WarnLevel Level = new(level("warn"))
)

func AllLevels

func AllLevels() []Level

type Logger

type Logger interface {
	Info(string)
	Debug(string)
	Error(whatWasHappeningWhenErrorOccurred string, err error)

	SetRequestIDFunc(RequestIDFunc)

	Clone() Logger
	WithName(string) Logger
	WithValues(map[string]any) Logger
	WithValue(string, any) Logger
	WithRequest(*http.Request) Logger
	WithResponse(response *http.Response) Logger
	WithError(error) Logger
	WithSpan(span trace.Span) Logger
}

Logger represents a simple logging interface we can build wrappers around. NOTICE: someone, naive and green, may be enticed to add a method to this interface akin to: WithQueryFilter(*types.QueryFilter) Logger This is a fool's errand, it would introduce a disallowed import cycle.

func EnsureLogger

func EnsureLogger(logger Logger) Logger

EnsureLogger guarantees that a Logger is available.

func NewNoopLogger

func NewNoopLogger() Logger

NewNoopLogger provides our noop Logger to dependency manager.

type RequestIDFunc

type RequestIDFunc func(*http.Request) string

RequestIDFunc fetches a string ID from a request.

type RequestInfo

type RequestInfo struct {
	Method    string
	Path      string
	Query     string
	RequestID string
}

RequestInfo holds HTTP request metadata extracted for logging.

func ExtractRequestInfo

func ExtractRequestInfo(req *http.Request, requestIDFunc RequestIDFunc) RequestInfo

ExtractRequestInfo extracts logging-relevant fields from an HTTP request.

type SpanInfo

type SpanInfo struct {
	SpanID  string
	TraceID string
}

SpanInfo holds span and trace IDs extracted from a trace.Span.

func ExtractSpanInfo

func ExtractSpanInfo(span trace.Span) SpanInfo

ExtractSpanInfo extracts span and trace IDs from a trace.Span.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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