logging

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext added in v0.20.0

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

FromContext extracts the logger from context If no logger is found, returns a disabled logger (no-op)

func GenerateSessionID added in v0.20.0

func GenerateSessionID() string

GenerateSessionID creates a unique session identifier. Format: YYYYMMDD_HHMMSS_xxxx (timestamp + 4 random hex chars) Example: 20251217_205106_a7b3

func New added in v0.20.0

func New(cfg Config) zerolog.Logger

New creates a new zerolog logger with the given configuration

func NewFromConfigValues added in v0.20.0

func NewFromConfigValues(level, format string) zerolog.Logger

NewFromConfigValues creates a logger from level and format strings. This is used by main.go to create a logger from the config package's LoggingConfig without creating an import cycle.

func NewFromEnv added in v0.20.0

func NewFromEnv() zerolog.Logger

NewFromEnv creates a logger based on environment variables DUMBER_LOG_LEVEL: trace, debug, info, warn, error (default: info) DUMBER_LOG_FORMAT: json, console (default: console)

func NewWithFile added in v0.20.0

func NewWithFile(cfg Config, fileCfg FileConfig) (zerolog.Logger, func(), error)

NewWithFile creates a logger that writes to stderr and/or a session log file. The session file uses JSON format for easy parsing by the CLI logs command. LogDir must exist before calling this function (handled by config.EnsureDirectories). Returns the logger and a cleanup function to close the file.

func ParseLevel added in v0.20.0

func ParseLevel(level string) zerolog.Level

ParseLevel converts a level string to zerolog.Level

func ParseSessionFilename added in v0.20.0

func ParseSessionFilename(filename string) (sessionID string, ok bool)

ParseSessionFilename extracts session info from a log filename. Example: "session_20251217_205106_a7b3.log" -> "20251217_205106_a7b3", true

func SessionFilename added in v0.20.0

func SessionFilename(sessionID string) string

SessionFilename generates the log filename for a session ID. Example: "20251217_205106_a7b3" -> "session_20251217_205106_a7b3.log"

func ShortSessionID added in v0.20.0

func ShortSessionID(sessionID string) string

ShortSessionID extracts the short ID (last 4 hex chars) from a full session ID. Example: "20251217_205106_a7b3" -> "a7b3"

func With added in v0.20.0

func With(ctx context.Context, fields map[string]any) context.Context

With creates a child logger with additional fields and returns a new context

func WithComponent added in v0.20.0

func WithComponent(ctx context.Context, component string) context.Context

WithComponent creates a child logger with a component field

func WithContext added in v0.20.0

func WithContext(ctx context.Context, logger zerolog.Logger) context.Context

WithContext returns a new context with the logger attached

func WithPaneID added in v0.20.0

func WithPaneID(ctx context.Context, paneID string) context.Context

WithPaneID creates a child logger with a pane_id field

func WithTabID added in v0.20.0

func WithTabID(ctx context.Context, tabID string) context.Context

WithTabID creates a child logger with a tab_id field

func WithURL added in v0.20.0

func WithURL(ctx context.Context, url string) context.Context

WithURL creates a child logger with a url field

Types

type Config added in v0.20.0

type Config struct {
	Level      zerolog.Level
	Format     string // "json" or "console"
	TimeFormat string
}

Config holds logging configuration

func DefaultConfig added in v0.20.0

func DefaultConfig() Config

DefaultConfig returns sensible defaults

type FileConfig added in v0.20.0

type FileConfig struct {
	Enabled       bool
	LogDir        string
	SessionID     string
	WriteToStderr bool // if false, logs go to file only (not stderr)
}

FileConfig holds file logging configuration

Jump to

Keyboard shortcuts

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