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 ¶
- func Ctx(ctx context.Context) *zerolog.Logger
- func Debug() *zerolog.Event
- func Default() zerolog.Logger
- func Error() *zerolog.Event
- func FromContext(ctx context.Context) *zerolog.Logger
- func Info() *zerolog.Event
- func New(cfg *Config) zerolog.Logger
- func RunID(ctx context.Context) string
- func SetDefault(logger zerolog.Logger)
- func Warn() *zerolog.Event
- func WithLogger(ctx context.Context, logger *zerolog.Logger) context.Context
- func WithProvider(ctx context.Context, providerID string) context.Context
- func WithRunID(ctx context.Context, runID string) context.Context
- func WithSource(ctx context.Context, source string) context.Context
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ctx ¶
Ctx returns a logger from the context or the default logger This is a shorter alias for FromContext.
func FromContext ¶
FromContext extracts the logger from context, or returns the default logger.
func SetDefault ¶
SetDefault atomically replaces the logger used by this package. It does not mutate zerolog's separate process-global logger or global level.
func WithLogger ¶
WithLogger adds a logger to the context.
func WithProvider ¶
WithProvider adds provider 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.