logger

package
v0.2.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Log is the global logger instance (file-only; nop before Init/NewLogger)
	Log zerolog.Logger
)

Functions

func ClearContext

func ClearContext()

ClearContext clears the project/agent context.

func Close added in v0.1.6

func Close() error

Close shuts down the logger, flushing any pending OTEL logs and closing the file writer. Call this on program shutdown for clean resource cleanup.

func CloseFileWriter deprecated

func CloseFileWriter() error

CloseFileWriter closes the file writer if it exists.

Deprecated: Use Close() which handles both file + OTEL shutdown.

func Debug

func Debug() *zerolog.Event

Debug logs a debug message (developer diagnostics, file-only)

func Error

func Error() *zerolog.Event

Error logs an error message (file-only)

func Fatal

func Fatal() *zerolog.Event

Fatal logs a fatal message and exits (file-only). NEVER use in Cobra hooks — return errors instead.

func GetLogFilePath

func GetLogFilePath() string

GetLogFilePath returns the path to the current log file, or empty string if file logging is disabled.

func Info

func Info() *zerolog.Event

Info logs an info message (file-only)

func Init

func Init()

Init initializes the global logger as a nop logger. This is the pre-file-logging placeholder — all log output is discarded until InitWithFile or NewLogger is called.

func InitWithFile deprecated

func InitWithFile(logsDir string, cfg *LoggingConfig) error

InitWithFile initializes the logger with file-only output.

Deprecated: Use NewLogger() for new code. This is retained for backwards compatibility.

func NewLogger added in v0.1.6

func NewLogger(opts *Options) error

NewLogger initializes the global logger with file output and optional OTEL bridge.

With OtelConfig nil: file-only logging via lumberjack. With OtelConfig set: file logging + OTEL hook that streams to the collector. OTEL SDK handles resilience natively — buffer, retry, drop on overflow.

If opts is nil or file logging is disabled, the logger becomes a nop.

func SetContext

func SetContext(project, agent string)

SetContext sets project and agent context for all subsequent log entries. Pass empty strings to clear. Thread-safe.

func Warn

func Warn() *zerolog.Event

Warn logs a warning message (file-only)

func WithField

func WithField(key string, value interface{}) zerolog.Logger

WithField returns a logger with an additional field

Types

type LoggingConfig

type LoggingConfig struct {
	FileEnabled *bool
	MaxSizeMB   int
	MaxAgeDays  int
	MaxBackups  int
	Compress    *bool
}

LoggingConfig holds configuration for file-based logging. This matches internal/config.LoggingConfig but is duplicated here to avoid circular imports.

func (*LoggingConfig) GetMaxAgeDays

func (c *LoggingConfig) GetMaxAgeDays() int

GetMaxAgeDays returns the max age in days, defaulting to 7 if not set.

func (*LoggingConfig) GetMaxBackups

func (c *LoggingConfig) GetMaxBackups() int

GetMaxBackups returns the max backups, defaulting to 3 if not set.

func (*LoggingConfig) GetMaxSizeMB

func (c *LoggingConfig) GetMaxSizeMB() int

GetMaxSizeMB returns the max size in MB, defaulting to 50 if not set.

func (*LoggingConfig) IsCompressEnabled added in v0.1.6

func (c *LoggingConfig) IsCompressEnabled() bool

IsCompressEnabled returns whether rotated log compression is enabled. Defaults to true if not explicitly set.

func (*LoggingConfig) IsFileEnabled

func (c *LoggingConfig) IsFileEnabled() bool

IsFileEnabled returns whether file logging is enabled. Defaults to true if not explicitly set.

type Options added in v0.1.6

type Options struct {
	LogsDir    string         // directory for log files
	FileConfig *LoggingConfig // file rotation settings
	OtelConfig *OtelLogConfig // nil = file-only, no OTEL bridge
}

Options configures the logger via NewLogger.

type OtelLogConfig added in v0.1.6

type OtelLogConfig struct {
	Endpoint       string        // e.g. "localhost:4318"
	Insecure       bool          // default: true (local collector)
	Timeout        time.Duration // export timeout
	MaxQueueSize   int           // batch processor queue size
	ExportInterval time.Duration // batch export interval
}

OtelLogConfig configures the OTEL zerolog bridge.

Directories

Path Synopsis
Package loggertest provides test doubles for the logger package.
Package loggertest provides test doubles for the logger package.

Jump to

Keyboard shortcuts

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