Documentation
¶
Overview ¶
Package logging provides structured logging capabilities for the goRAG framework. It offers a simple, flexible logging interface with support for multiple log levels, file and console output, and structured field logging.
The API is designed to mirror uber-go/zap's calling convention:
logger.Info("server started", "port", 8080, "host", "localhost")
logger.Warn("slow request", "duration", 2.5*time.Second)
logger.Error("connection failed", err, "addr", "127.0.0.1:3306")
logger.Debug("cache hit", "key", userID)
The package provides three main implementations:
- Console logger: Outputs to stdout with minimal formatting
- File logger: Writes to a file with configurable log level
- No-op logger: Discards all log output (useful for testing)
- Zap logger: High-performance logger with log rotation (requires zap dependency)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Level ¶
type Level int
Level represents the severity level of a log message. Log levels are ordered from least to most severe: DEBUG < INFO < WARN < ERROR.
const ( // DEBUG level is for detailed debugging information. DEBUG Level = iota // INFO level is for general operational information. INFO // WARN level is for warning messages that indicate potential issues. WARN // ERROR level is for error messages indicating failures. ERROR )
Log level constants define the severity of log messages. Messages with a level below the configured threshold will not be logged.
type Logger ¶
type Logger interface {
// Info logs an informational message with optional key-value pairs.
Info(msg string, keyvals ...any)
// Error logs an error message. The error is automatically included in the output.
// Additional key-value pairs can be provided after the error.
Error(msg string, err error, keyvals ...any)
// Debug logs a debug message with optional key-value pairs.
Debug(msg string, keyvals ...any)
// Warn logs a warning message with optional key-value pairs.
Warn(msg string, keyvals ...any)
}
Logger defines the interface for structured logging. All methods accept optional key-value pairs (alternating string keys and any values), following the same convention as uber-go/zap.
Example:
logger.Info("user logged in", "user_id", 123, "ip", "192.168.1.1")
logger.Error("database error", err, "query", sql)
logger.Warn("rate limit approaching", "remaining", 5)
logger.Debug("processing chunk", "chunkID", chunk.ID)
func DefaultConsoleLogger ¶
func DefaultConsoleLogger() Logger
DefaultConsoleLogger creates a logger that writes to stdout with INFO level.
func DefaultFileLogger ¶
DefaultFileLogger creates a logger that writes to a file. The file is created if it doesn't exist, and appended to if it does.
func DefaultNoopLogger ¶
func DefaultNoopLogger() Logger
DefaultNoopLogger creates a logger that discards all output.
func DefaultZapLogger ¶
DefaultZapLogger creates a high-performance logger using uber-go/zap with lumberjack for log rotation.
type Option ¶
type Option func(*defaultLogger)
Option is a function that configures a defaultLogger.
type ZapConfig ¶
type ZapConfig struct {
// Filename is the file to write logs to.
Filename string
// MaxSize is the maximum size in megabytes of the log file before it gets rotated.
MaxSize int
// MaxBackups is the maximum number of old log files to retain.
MaxBackups int
// MaxAge is the maximum number of days to retain old log files.
MaxAge int
// Compress determines if the rotated log files should be compressed using gzip.
Compress bool
// Console specifies if logs should also be printed to standard output.
Console bool
}
ZapConfig defines the options for the Zap rolling logger