Documentation
¶
Index ¶
- Variables
- func ClearContext()
- func Close() error
- func CloseFileWriter() errordeprecated
- func Debug() *zerolog.Event
- func Error() *zerolog.Event
- func Fatal() *zerolog.Event
- func GetLogFilePath() string
- func Info() *zerolog.Event
- func Init()
- func InitWithFile(logsDir string, cfg *LoggingConfig) errordeprecated
- func NewLogger(opts *Options) error
- func SetContext(project, agent string)
- func Warn() *zerolog.Event
- func WithField(key string, value interface{}) zerolog.Logger
- type LoggingConfig
- type Options
- type OtelLogConfig
Constants ¶
This section is empty.
Variables ¶
var ( // Log is the global logger instance (file-only; nop before Init/NewLogger) Log zerolog.Logger )
Functions ¶
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 Fatal ¶
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 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
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.
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. |