Documentation
¶
Overview ¶
Package logger provides structured logging with file and console output.
Index ¶
- Constants
- func GetLogPath(opts LoggerOptions) string
- func PrintLogFile(w io.Writer, opts LoggerOptions) error
- type ConsoleHandler
- type Logger
- type LoggerInterface
- type LoggerOptions
- type NoOpLogger
- func (n *NoOpLogger) Close()
- func (n *NoOpLogger) Debug(msg string, args ...any)
- func (n *NoOpLogger) Error(msg string, args ...any)
- func (n *NoOpLogger) GetLogPath() string
- func (n *NoOpLogger) Info(msg string, args ...any)
- func (n *NoOpLogger) Trace(msg string, args ...any)
- func (n *NoOpLogger) Warn(msg string, args ...any)
Constants ¶
const ( // DefaultLogMaxSize is the default maximum size in megabytes before log rotation DefaultLogMaxSize = 2 // DefaultLogMaxBackups is the default number of old log files to retain DefaultLogMaxBackups = 3 // DefaultLogMaxAge is the default maximum number of days to retain old log files DefaultLogMaxAge = 28 // LevelTrace is a custom log level below Debug, only logged to file LevelTrace = slog.LevelDebug - 4 )
Variables ¶
This section is empty.
Functions ¶
func GetLogPath ¶
func GetLogPath(opts LoggerOptions) string
GetLogPath returns the path where logs will be written based on options
func PrintLogFile ¶
func PrintLogFile(w io.Writer, opts LoggerOptions) error
PrintLogFile prints the current log file to the provided writer If writer is nil, prints to stdout. Returns error if log file doesn't exist or can't be read.
Types ¶
type ConsoleHandler ¶
type ConsoleHandler struct {
// contains filtered or unexported fields
}
ConsoleHandler is a simple handler that outputs clean messages to console
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger handles dual output logging (file + console)
func NewLogger ¶
func NewLogger(opts LoggerOptions) (*Logger, error)
NewLogger creates a new logger instance
func (*Logger) Close ¶
func (l *Logger) Close()
Close closes the log file and flushes any buffered data
func (*Logger) GetLogPath ¶
GetLogPath returns the path to the current log file
type LoggerInterface ¶
type LoggerInterface interface {
Trace(msg string, args ...any) // Only logs to file, never to console
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, args ...any)
Close()
GetLogPath() string
}
LoggerInterface defines the logging methods
type LoggerOptions ¶
type LoggerOptions struct {
Verbose bool
LogDir string // If empty, uses %LOCALAPPDATA%\smpc
MaxSize int // Max size in megabytes before rotation (default: 10)
MaxBackups int // Max number of old log files to keep (default: 3)
MaxAge int // Max days to keep old log files (default: 28)
Compress bool // Whether to compress rotated logs (default: true)
}
LoggerOptions configures the logger
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger is a logger that does nothing - useful for tests
func NewNoOpLogger ¶
func NewNoOpLogger() *NoOpLogger
NewNoOpLogger creates a new no-op logger for testing
func (*NoOpLogger) Close ¶
func (n *NoOpLogger) Close()
func (*NoOpLogger) Debug ¶
func (n *NoOpLogger) Debug(msg string, args ...any)
func (*NoOpLogger) Error ¶
func (n *NoOpLogger) Error(msg string, args ...any)
func (*NoOpLogger) GetLogPath ¶
func (n *NoOpLogger) GetLogPath() string
func (*NoOpLogger) Info ¶
func (n *NoOpLogger) Info(msg string, args ...any)
func (*NoOpLogger) Trace ¶
func (n *NoOpLogger) Trace(msg string, args ...any)
func (*NoOpLogger) Warn ¶
func (n *NoOpLogger) Warn(msg string, args ...any)