logging

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConsoleTimeFormat = "15:04:05"
)

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 InitStartupTrace added in v0.26.0

func InitStartupTrace(logLevel string)

InitStartupTrace initializes the global startup trace. Call this as early as possible in main() to capture T0. The trace is enabled only if the given log level is debug or trace.

func InstallGLibLogHandler added in v0.26.0

func InstallGLibLogHandler(ctx context.Context, logger zerolog.Logger, enableDebug bool)

InstallGLibLogHandler installs a custom GLib log handler that routes GTK4/WebKitGTK6/GLib messages to the provided zerolog logger. This must be called before GTK/WebKit initialization. The handler captures messages from all GLib-based libraries (GTK, GDK, WebKit, etc.) If enableDebug is true, GLib debug messages will also be captured (useful when log level is debug/trace).

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 NewFromConfigValuesWithTimeFormat added in v0.22.0

func NewFromConfigValuesWithTimeFormat(level, format, timeFormat string) zerolog.Logger

NewFromConfigValuesWithTimeFormat creates a logger from level/format and overrides time format.

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 TruncateURL added in v0.26.0

func TruncateURL(url string, maxLen int) string

TruncateURL truncates a URL to maxLen characters for logging.

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

type Milestone added in v0.26.0

type Milestone struct {
	Name    string
	Elapsed time.Duration // time since t0
	Delta   time.Duration // time since previous milestone
}

Milestone represents a timing checkpoint during startup.

type StartupTrace added in v0.26.0

type StartupTrace struct {
	// contains filtered or unexported fields
}

StartupTrace tracks cold start milestones from process launch to first paint. Thread-safe for use across goroutines. Enabled only when log level is debug or trace.

func Trace added in v0.26.0

func Trace() *StartupTrace

Trace returns the global startup trace instance. Returns a no-op trace if not initialized or disabled.

func (*StartupTrace) Enabled added in v0.26.0

func (st *StartupTrace) Enabled() bool

Enabled returns whether the trace is active.

func (*StartupTrace) Finish added in v0.26.0

func (st *StartupTrace) Finish()

Finish marks the startup trace as complete and emits a summary. Called on first_paint milestone.

func (*StartupTrace) Mark added in v0.26.0

func (st *StartupTrace) Mark(name string)

Mark records a milestone with the given name. Emits a debug log line showing elapsed time and delta from previous milestone.

func (*StartupTrace) SetLogger added in v0.26.0

func (st *StartupTrace) SetLogger(logger *zerolog.Logger)

SetLogger sets the logger for emitting milestone logs. Flushes any buffered milestones that were recorded before the logger was set.

func (*StartupTrace) TotalElapsed added in v0.26.0

func (st *StartupTrace) TotalElapsed() time.Duration

TotalElapsed returns the total time since T0.

func (*StartupTrace) UpdateLogger added in v0.26.0

func (st *StartupTrace) UpdateLogger(logger *zerolog.Logger)

UpdateLogger updates the logger and re-emits all milestones to the new logger. Call this after the session file logger is available to capture milestones in the log file.

Jump to

Keyboard shortcuts

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