Documentation
¶
Index ¶
- func Debug(msg string, args ...any)
- func Error(msg string, args ...any)
- func Fatal(msg string, args ...any)
- func Info(msg string, args ...any)
- func Warn(msg string, args ...any)
- type Config
- type LogLevel
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Fatal(msg string, args ...any)
- func (l *Logger) GetConfig() Config
- func (l *Logger) GetLevel() LogLevel
- func (l *Logger) IsDebugEnabled() bool
- func (l *Logger) IsErrorEnabled() bool
- func (l *Logger) IsInfoEnabled() bool
- func (l *Logger) IsWarningEnabled() bool
- func (l *Logger) WithOptions(opts ...Option) *Logger
- type Option
- func WithCaller() Option
- func WithCompression() Option
- func WithDebugLevel() Option
- func WithDefaultFormat() Option
- func WithErrorLevel() Option
- func WithInfoLevel() Option
- func WithJSONFormat() Option
- func WithLevel(level LogLevel) Option
- func WithLevelOff() Option
- func WithMaxAge(days int) Option
- func WithMaxBackups(count int) Option
- func WithMaxSize(sizeMB int) Option
- func WithOutputFile(file string) Option
- func WithWarningLevel() Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶ added in v0.0.2
type Config struct {
Level LogLevel // Minimum log level to output
OutputFile string // Path to log file (empty for stdout)
MaxAgeDays int // Maximum number of days to retain old log files
MaxBackups int // Maximum number of old log files to retain
MaxSizeMB int // Maximum size in megabytes of the log file before rotation
Compress bool // Whether to compress rotated log files
JSONFormat bool // Whether to use JSON formatting
UseDefault bool // Whether to use slog.Default() format instead of custom handler
AddCaller bool // Whether to add caller information (file and line number)
}
Config holds all configurable parameters for the logger
type LogLevel ¶
type LogLevel string
LogLevel represents the severity levels for log messages
const ( LevelDebug LogLevel = "debug" // Debug level for detailed debugging information LevelInfo LogLevel = "info" // Info level for general operational messages LevelWarning LogLevel = "warning" // Warning level for potentially harmful situations LevelError LogLevel = "error" // Error level for error events LevelOff LogLevel = "off" // Off level completely disables logging )
Supported log levels constants
type Logger ¶
type Logger struct {
*slog.Logger // Embedded slog.Logger for core logging functionality
// contains filtered or unexported fields
}
Logger is the main logger struct that wraps slog.Logger with additional features
func Default ¶
func Default() *Logger
Default returns a new logger using slog.Default() configuration Output format: "2025/05/31 09:00:08 INFO Application started version=1.0.0 config=default"
func New ¶
New creates a new Logger instance with customizable options Default configuration:
- Level: info
- MaxAgeDays: 7
- MaxBackups: 3
- MaxSizeMB: 100
- Format: text
- Output: stdout
- AddCaller: false
func (*Logger) Close ¶
Close releases resources used by the logger (primarily file handles) Should be called when the logger is no longer needed
func (*Logger) GetConfig ¶ added in v0.0.2
GetConfig returns a copy of the current logger configuration
func (*Logger) IsDebugEnabled ¶
IsDebugEnabled returns true if debug level logging is enabled
func (*Logger) IsErrorEnabled ¶ added in v0.0.2
IsErrorEnabled returns true if error level logging is enabled
func (*Logger) IsInfoEnabled ¶ added in v0.0.2
IsInfoEnabled returns true if info level logging is enabled
func (*Logger) IsWarningEnabled ¶ added in v0.0.2
IsWarningEnabled returns true if warning level logging is enabled
func (*Logger) WithOptions ¶ added in v0.0.2
WithOptions creates a new Logger instance with additional configuration options applied Returns a new Logger instance, leaving the original unchanged (immutable pattern)
type Option ¶ added in v0.0.2
type Option func(*Config)
Option defines the type for configuration functions that modify Logger settings
func WithCaller ¶ added in v0.0.3
func WithCaller() Option
WithCaller enables including caller information (file and line number) in logs
func WithCompression ¶ added in v0.0.2
func WithCompression() Option
WithCompression enables compression of rotated log files
func WithDefaultFormat ¶ added in v0.0.2
func WithDefaultFormat() Option
WithDefaultFormat configures the logger to use slog.Default() format
func WithJSONFormat ¶ added in v0.0.2
func WithJSONFormat() Option
WithJSONFormat enables JSON formatting for log output
func WithMaxAge ¶ added in v0.0.2
WithMaxAge sets maximum days to retain log files
func WithMaxBackups ¶
WithMaxBackups sets maximum number of old log files to keep
func WithMaxSize ¶
WithMaxSize sets maximum log file size in megabytes before rotation
func WithOutputFile ¶ added in v0.0.2
WithOutputFile configures file output with the given path