api

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LoggerContextKey contextKey = "logger"
	TraceIDKey       contextKey = "trace-id"
	ComponentKey     contextKey = "component"
)

Variables

This section is empty.

Functions

func GetTraceIDFromContext

func GetTraceIDFromContext(ctx context.Context) string

Types

type DefaultLogger

type DefaultLogger struct{}

DefaultLogger is a no-op logger that satisfies the api.Logger interface

func (*DefaultLogger) AddField

func (d *DefaultLogger) AddField(key string, value interface{}) Logger

func (*DefaultLogger) Debug

func (d *DefaultLogger) Debug(ctx context.Context, msg string, args ...Field)

func (*DefaultLogger) Error

func (d *DefaultLogger) Error(ctx context.Context, msg string, err error, args ...Field)

func (*DefaultLogger) Fatal

func (d *DefaultLogger) Fatal(ctx context.Context, msg string, err error, args ...Field)

func (*DefaultLogger) Info

func (d *DefaultLogger) Info(ctx context.Context, msg string, args ...Field)

func (*DefaultLogger) ToContext

func (d *DefaultLogger) ToContext(ctx context.Context) context.Context

func (*DefaultLogger) Warn

func (d *DefaultLogger) Warn(ctx context.Context, msg string, args ...Field)

func (*DefaultLogger) WithComponent

func (d *DefaultLogger) WithComponent(component string) Logger

func (*DefaultLogger) WithFields

func (d *DefaultLogger) WithFields(fields ...Field) Logger

func (*DefaultLogger) WithTraceID

func (d *DefaultLogger) WithTraceID(traceID string) Logger

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field represents a key-value pair in structured logging

func Any

func Any(key string, val interface{}) Field

func Bool

func Bool(key string, val bool) Field

func Duration

func Duration(key string, val time.Duration) Field

func ErrorField

func ErrorField(err error) Field

ErrorField returns a Field representing an error

func Int

func Int(key string, val int) Field

func Int64

func Int64(key string, val int64) Field

func String

func String(key string, val string) Field

Common field constructors

func (Field) String

func (f Field) String() string

type Logger

type Logger interface {
	// Context-first logging methods - automatically extract trace_id from context
	Debug(ctx context.Context, msg string, fields ...Field)
	Info(ctx context.Context, msg string, fields ...Field)
	Warn(ctx context.Context, msg string, fields ...Field)
	Error(ctx context.Context, msg string, err error, fields ...Field)
	Fatal(ctx context.Context, msg string, err error, fields ...Field)

	// Builder methods for adding metadata
	WithTraceID(traceID string) Logger
	WithFields(fields ...Field) Logger
	WithComponent(component string) Logger
	AddField(key string, value interface{}) Logger

	// Context integration
	ToContext(ctx context.Context) context.Context
}

Logger defines the core logging interface with context-first design. All logging methods take context.Context as the first parameter to automatically extract trace_id and other request-scoped metadata. Implementations can wrap different logging libraries like zerolog, zap, logrus, etc.

func GetLoggerFromContext

func GetLoggerFromContext(ctx context.Context) Logger

Jump to

Keyboard shortcuts

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