logger

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 2 Imported by: 0

README

internal/logger

Pattern used

  • Consumer-owned logging interface. Usecase and delivery depend on Logger, not concrete implementations.

How to extend

  • Add methods to Logger only when needed by app layers.
  • Implement under internal/infra/logger/; wire in app.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextFieldsProviderFunc

type ContextFieldsProviderFunc func(ctx context.Context) Fields

ContextFieldsProviderFunc extracts context-bound fields (e.g. request/trace IDs) for every log and sink export.

type Fields

type Fields map[string]any

Fields is a logger-agnostic key/value hashmap.

func CloneFields

func CloneFields(fields Fields) Fields

CloneFields returns a shallow copy of fields. Nested values (maps, slices, pointers) are shared.

func FromPairs

func FromPairs(pairs ...any) Fields

FromPairs creates fields from key/value pairs. If pairs length is odd, the last key is ignored.

func MergeFields

func MergeFields(fieldSets ...Fields) Fields

func OptionalFields

func OptionalFields(optionalFields ...Fields) Fields

OptionalFields returns the first variadic Fields argument, or nil if none provided.

type LogSinkFunc

type LogSinkFunc func(ctx context.Context, severity Severity, message string, fields ...Fields)

LogSinkFunc is an optional secondary sink for structured logs. The primary sink can stay terminal/stdout; this sink can export to any backend without coupling the logger API.

type Logger

type Logger interface {
	Debug(ctx context.Context, message string, fields ...Fields)
	Info(ctx context.Context, message string, fields ...Fields)
	Warn(ctx context.Context, message string, fields ...Fields)
	Error(ctx context.Context, message string, err error, fields ...Fields)
	// ErrorNoStack logs at error level without stack trace for expected failures.
	ErrorNoStack(ctx context.Context, message string, err error, fields ...Fields)
	// SetLogSink sets a secondary log sink. Must be called during startup before concurrent logging begins.
	SetLogSink(sink LogSinkFunc)
	// SetContextFieldsProvider sets the provider for context-bound fields. Must be called during startup before concurrent logging begins.
	SetContextFieldsProvider(provider ContextFieldsProviderFunc)
	Sync() error
}

Logger defines the project logging contract. Context is included in every call so tracing metadata can be attached later without changing call sites.

type NoopLogger added in v0.5.0

type NoopLogger struct{}

NoopLogger is a no-op implementation of Logger.

func (NoopLogger) Debug added in v0.5.0

func (n NoopLogger) Debug(ctx context.Context, message string, fields ...Fields)

func (NoopLogger) Error added in v0.5.0

func (n NoopLogger) Error(ctx context.Context, message string, err error, fields ...Fields)

func (NoopLogger) ErrorNoStack added in v0.5.0

func (n NoopLogger) ErrorNoStack(ctx context.Context, message string, err error, fields ...Fields)

func (NoopLogger) Info added in v0.5.0

func (n NoopLogger) Info(ctx context.Context, message string, fields ...Fields)

func (NoopLogger) SetContextFieldsProvider added in v0.5.0

func (n NoopLogger) SetContextFieldsProvider(provider ContextFieldsProviderFunc)

func (NoopLogger) SetLogSink added in v0.5.0

func (n NoopLogger) SetLogSink(sink LogSinkFunc)

func (NoopLogger) Sync added in v0.5.0

func (n NoopLogger) Sync() error

func (NoopLogger) Warn added in v0.5.0

func (n NoopLogger) Warn(ctx context.Context, message string, fields ...Fields)

type Severity

type Severity uint8
const (
	SeverityDebug Severity = iota
	SeverityInfo
	SeverityWarn
	SeverityError
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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