logger

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

pkg/logger

logger is a thin wrapper over zerolog that adds request-scoped context keys and a single Init call for global level configuration.

logger.Init("info")  // call once at startup; accepts debug/info/warn/error/fatal/panic

logger.Info().Msg("reconciler started")
logger.Error().Err(err).Msg("reconcile failed")

Level initialisation

Init(level string) sets the global zerolog level. Any unrecognised level string defaults to info. Call it once in main after reading ORK_ENV or a --log-level flag.

Context-scoped logging

Reconcile loops and HTTP handlers propagate three values through context.Context:

Key Type Added by Read by
request_id string logger.WithRequestID(ctx) logger.FromContext(ctx)
crd string logger.WithCRD(ctx, name) logger.FromContext(ctx)
resource string logger.WithResource(ctx, key) logger.FromContext(ctx)

FromContext builds a logger that includes whichever of the three are present:

ctx = logger.WithCRD(ctx, "myApp")
ctx = logger.WithRequestID(ctx)

log := logger.FromContext(ctx)
log.Info().Msg("starting reconcile")
// → {"level":"info","crd":"myApp","request_id":"<uuid>","message":"starting reconcile"}

Direct logging

For code paths without a context, use the package-level functions directly:

logger.Debug().Str("key", val).Msg("details")
logger.Warn().Err(err).Msg("retrying")
logger.Fatal().Err(err).Msg("cannot start")  // calls os.Exit(1)

Documentation

Overview

pkg/logger/context.go

Index

Constants

View Source
const (
	RequestIDKey contextKey = "request_id"
	CRDKey       contextKey = "crd"
	ResourceKey  contextKey = "resource"
)

Variables

This section is empty.

Functions

func Debug

func Debug() *zerolog.Event

func Error

func Error() *zerolog.Event

func Fatal

func Fatal() *zerolog.Event

func FromContext

func FromContext(ctx context.Context) *zerolog.Logger

func Info

func Info() *zerolog.Event

func Init

func Init(level string)

func Panic

func Panic() *zerolog.Event

func Warn

func Warn() *zerolog.Event

func WithCRD

func WithCRD(ctx context.Context, crd string) context.Context

func WithRequestID

func WithRequestID(ctx context.Context) context.Context

func WithResource

func WithResource(ctx context.Context, key string) context.Context

Types

This section is empty.

Jump to

Keyboard shortcuts

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