logging

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

README

logging

Package logging provides structured logging with zerolog for consistent application-wide logging.

logging

import "github.com/agentstation/starmap/pkg/logging"

Package logging provides structured logging for the starmap system using zerolog. It offers high-performance, zero-allocation logging with support for both human-readable console output during development and structured JSON output for production environments.

Example usage:

// Get the default logger
log := logging.Default()
log.Info().Str("provider", "openai").Msg("Fetching models")

// Create a logger with context
ctx := logging.WithLogger(context.Background(), log)
ctxLog := logging.FromContext(ctx)
ctxLog.Debug().Msg("Using logger from context")

// Add structured fields
log.Error().
    Err(err).
    Str("provider_id", "anthropic").
    Int("retry_count", 3).
    Msg("Failed to fetch models")

Index

func Ctx

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

Ctx returns a logger from the context or the default logger This is a shorter alias for FromContext.

func Debug

func Debug() *zerolog.Event

Debug starts a new debug level log event.

func Default

func Default() zerolog.Logger

Default returns a copy of the default logger.

func Error

func Error() *zerolog.Event

Error starts a new error level log event.

func FromContext

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

FromContext extracts the logger from context, or returns the default logger.

func Info

func Info() *zerolog.Event

Info starts a new info level log event.

func New

func New(cfg *Config) zerolog.Logger

New creates a logger from cfg without changing process-global zerolog state.

func RunID

func RunID(ctx context.Context) string

RunID extracts the run correlation ID from context.

func SetDefault

func SetDefault(logger zerolog.Logger)

SetDefault atomically replaces the logger used by this package. It does not mutate zerolog's separate process-global logger or global level.

func Warn

func Warn() *zerolog.Event

Warn starts a new warning level log event.

func WithLogger

func WithLogger(ctx context.Context, logger *zerolog.Logger) context.Context

WithLogger adds a logger to the context.

func WithProvider

func WithProvider(ctx context.Context, providerID string) context.Context

WithProvider adds provider context to the logger.

func WithRunID

func WithRunID(ctx context.Context, runID string) context.Context

WithRunID adds a run correlation ID to the context logger.

func WithSource

func WithSource(ctx context.Context, source string) context.Context

WithSource adds source context to the logger.

type Config

Config holds logger configuration options.

type Config struct {
    // Level is the minimum log level to output
    Level string

    // Format is the output format (json, console, pretty)
    Format string

    // Output is where to write logs (stderr, stdout, discard, or none).
    Output string

    // TimeFormat for timestamps (kitchen, rfc3339, unix, etc.)
    TimeFormat string

    // NoColor disables color output in console mode
    NoColor bool

    // AddCaller includes file:line in log output
    AddCaller bool

    // Fields are default fields to include in all logs
    Fields map[string]any
}

Generated by gomarkdoc

Documentation

Overview

Package logging provides structured logging for the starmap system using zerolog. It offers high-performance, zero-allocation logging with support for both human-readable console output during development and structured JSON output for production environments.

Example usage:

// Get the default logger
log := logging.Default()
log.Info().Str("provider", "openai").Msg("Fetching models")

// Create a logger with context
ctx := logging.WithLogger(context.Background(), log)
ctxLog := logging.FromContext(ctx)
ctxLog.Debug().Msg("Using logger from context")

// Add structured fields
log.Error().
    Err(err).
    Str("provider_id", "anthropic").
    Int("retry_count", 3).
    Msg("Failed to fetch models")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx

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

Ctx returns a logger from the context or the default logger This is a shorter alias for FromContext.

func Debug

func Debug() *zerolog.Event

Debug starts a new debug level log event.

func Default

func Default() zerolog.Logger

Default returns a copy of the default logger.

func Error

func Error() *zerolog.Event

Error starts a new error level log event.

func FromContext

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

FromContext extracts the logger from context, or returns the default logger.

func Info

func Info() *zerolog.Event

Info starts a new info level log event.

func New

func New(cfg *Config) zerolog.Logger

New creates a logger from cfg without changing process-global zerolog state.

func RunID added in v0.1.0

func RunID(ctx context.Context) string

RunID extracts the run correlation ID from context.

func SetDefault

func SetDefault(logger zerolog.Logger)

SetDefault atomically replaces the logger used by this package. It does not mutate zerolog's separate process-global logger or global level.

func Warn

func Warn() *zerolog.Event

Warn starts a new warning level log event.

func WithLogger

func WithLogger(ctx context.Context, logger *zerolog.Logger) context.Context

WithLogger adds a logger to the context.

func WithProvider

func WithProvider(ctx context.Context, providerID string) context.Context

WithProvider adds provider context to the logger.

func WithRunID added in v0.1.0

func WithRunID(ctx context.Context, runID string) context.Context

WithRunID adds a run correlation ID to the context logger.

func WithSource

func WithSource(ctx context.Context, source string) context.Context

WithSource adds source context to the logger.

Types

type Config

type Config struct {
	// Level is the minimum log level to output
	Level string

	// Format is the output format (json, console, pretty)
	Format string

	// Output is where to write logs (stderr, stdout, discard, or none).
	Output string

	// TimeFormat for timestamps (kitchen, rfc3339, unix, etc.)
	TimeFormat string

	// NoColor disables color output in console mode
	NoColor bool

	// AddCaller includes file:line in log output
	AddCaller bool

	// Fields are default fields to include in all logs
	Fields map[string]any
}

Config holds logger configuration options.

Jump to

Keyboard shortcuts

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