logger

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 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)
	// 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 Severity

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

Jump to

Keyboard shortcuts

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