logging

package
v0.0.0-...-d09923a Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: LGPL-2.1 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldIdempotencyId = "idempotency_id"
	FieldTenantId      = "tenant_id"
	FieldOrgId         = "org_id"

	FieldServiceName = "service.name"
)

Variables

This section is empty.

Functions

func InitSubModule

func InitSubModule()

func NewErrReport

func NewErrReport(err error, skipStacktrace bool) *errReport

func NewJsonCodec

func NewJsonCodec(skipStacktrace bool) errors.Codec

NewJsonCodec encodes error data as JSON documents. If `pretty` is set to `true` the output will be indented for readability.

func NewTelemetryHandler

func NewTelemetryHandler(out io.Writer, level slog.Leveler) slog.Handler

func RegisterContextFields

func RegisterContextFields(hook ContextFieldsFn)

func SetResourceFields

func SetResourceFields(fields map[string]string)

SetResourceFields is called by telemetry once its resource is built; until then the resource fields are null.

func WithHttpFields

func WithHttpFields(ctx context.Context, fields HttpFields) context.Context

Types

type Attr

type Attr map[string]any

type ContextFieldsFn

type ContextFieldsFn func(ctx context.Context) map[string]any

ContextFieldsFn reads operation fields (idempotency_id, tenant_id, org_id) from ctx. It exists because the packages that own those values import logging, so logging cannot import them.

type HttpFields

type HttpFields struct {
	Method     string
	Route      string
	StatusCode int
	DurationMs float64
}

HttpFields are the access-log fields. They reach the top level of a record only through WithHttpFields, never through caller data.

func HttpFieldsOf

func HttpFieldsOf(ctx context.Context) (HttpFields, bool)

type Level

type Level string
const (
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

type LoggerService

type LoggerService interface {
	InnerLogger() any
	Clone() LoggerService
	Level() Level
	SetLevel(lvl Level)
	Debug(ctx context.Context, message string, data Attr)
	Debugf(ctx context.Context, format string, args ...any)
	Info(ctx context.Context, message string, data Attr)
	Infof(ctx context.Context, format string, args ...any)
	Warn(ctx context.Context, message string, data Attr)
	Warnf(ctx context.Context, format string, args ...any)
	Error(ctx context.Context, message string, err error)
	Errorf(ctx context.Context, format string, args ...any)
}

LoggerService takes ctx on every write so each record carries the span, idempotency id, tenant and org active at that point, not those of the place the logger was obtained. Code with no operation (boot, shutdown, CLI) passes context.Background(): the fields are null.

func Logger

func Logger() LoggerService

func NewLogger

func NewLogger(levels ...Level) LoggerService

func NewLoggerTo

func NewLoggerTo(out io.Writer, levels ...Level) LoggerService

NewLoggerTo writes to out instead of stdout; tests read the JSON lines back from it.

Jump to

Keyboard shortcuts

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