Documentation
¶
Overview ¶
Package logger provides structured logging capabilities for the doppel duplicate file finder.
This package wraps Go's slog package to provide consistent logging across the application with support for multiple output formats:
- Pretty: Human-readable colored output for development
- JSON: Structured JSON output for automation and monitoring
- Text: Plain text output for simple logging needs
The package supports configurable log levels, output destinations, and provides both global logger functions and instance-based logging.
Index ¶
- func Debug(msg string, args ...any)
- func DebugAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func DebugCtx(ctx context.Context, msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func ErrorCtx(ctx context.Context, msg string, args ...any)
- func Info(msg string, args ...any)
- func InfoAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func InfoCtx(ctx context.Context, msg string, args ...any)
- func NewDefault(config *Config) error
- func ResetDefault()
- func SetDefault(logger *Logger) error
- func Warn(msg string, args ...any)
- func WarnAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func WarnCtx(ctx context.Context, msg string, args ...any)
- type Config
- type JSONHandler
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Handler() slog.Handler
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Log(ctx context.Context, level slog.Level, msg string, args ...any)
- func (l *Logger) LogAttrs(ctx context.Context, level slog.Level, message string, attrs ...slog.Attr)
- func (l *Logger) Logger() *slog.Logger
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnAttrs(ctx context.Context, message string, attrs ...slog.Attr)
- func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithGroup(name string) *Logger
- type PrettyHandler
- type TextHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugAttrs ¶
DebugAttrs logs a debug message with attributes.
func ErrorAttrs ¶
ErrorAttrs logs an error message with attributes.
func NewDefault ¶
NewDefault creates a new default logger with the provided configuration.
func ResetDefault ¶
func ResetDefault()
ResetDefault resets the default logger to the standard slog.Default logger.
func SetDefault ¶
SetDefault sets the default logger to the provided logger.
Types ¶
type Config ¶
type Config struct {
// Format specifies the log format (e.g., "text", "json", "pretty", etc.)
Format string
// Writer is the output destination for the logs (e.g., [os.Stdout], [os.Stderr], or a file)
Writer io.Writer
// Options holds additional options for the slog.Handler
Options *slog.HandlerOptions
}
Config holds the configuration for the logger.
type JSONHandler ¶
type JSONHandler struct {
// contains filtered or unexported fields
}
JSONHandler is a slog.JSONHandler with the corrected source position of the caller.
func NewJSONHandler ¶
func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) *JSONHandler
NewJSONHandler creates a JSONHandler that writes to w, using the given options. If opts is nil, the default options are used.
func (*JSONHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*JSONHandler) Handle ¶
Handle formats its slog.Record argument as a JSON object on a single line.
func (*JSONHandler) WithAttrs ¶
func (h *JSONHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a new JSONHandler whose attributes consists of h's attributes followed by attrs.
func (*JSONHandler) WithGroup ¶
func (h *JSONHandler) WithGroup(name string) slog.Handler
WithGroup returns a new JSONHandler with the given group appended to h's groups.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a wrapper around slog.Logger with additional configuration and convenience methods for logging at different levels.
func (*Logger) DebugAttrs ¶
DebugAttrs logs a debug message with attributes.
func (*Logger) DebugContext ¶
DebugContext logs a debug message with context.
func (*Logger) ErrorAttrs ¶
ErrorAttrs logs an error message with attributes.
func (*Logger) ErrorContext ¶
ErrorContext logs an error message with context.
func (*Logger) Handler ¶
Handler returns the underlying slog.Handler used by the logger.
func (*Logger) InfoContext ¶
InfoContext logs an informational message with context.
func (*Logger) LogAttrs ¶
func (l *Logger) LogAttrs(ctx context.Context, level slog.Level, message string, attrs ...slog.Attr)
LogAttrs logs a message with attributes at the specified level.
func (*Logger) Logger ¶
Logger returns the underlying slog.Logger instance.
func (*Logger) WarnContext ¶
WarnContext logs a warning message with context.
type PrettyHandler ¶
type PrettyHandler struct {
// contains filtered or unexported fields
}
PrettyHandler implements slog.Handler for human-friendly terminal output.
func NewPrettyHandler ¶
func NewPrettyHandler(w io.Writer, opts *slog.HandlerOptions) *PrettyHandler
NewPrettyHandler creates a new pretty handler.
func (*PrettyHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*PrettyHandler) WithAttrs ¶
func (h *PrettyHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a new PrettyHandler whose attributes consists of h's attributes followed by attrs.
func (*PrettyHandler) WithGroup ¶
func (h *PrettyHandler) WithGroup(name string) slog.Handler
WithGroup returns a new PrettyHandler with the given group appended to h's groups.
type TextHandler ¶
type TextHandler struct {
// contains filtered or unexported fields
}
TextHandler is a slog.TextHandler with the corrected source position of the caller.
func NewTextHandler ¶
func NewTextHandler(w io.Writer, opts *slog.HandlerOptions) *TextHandler
NewTextHandler creates a TextHandler that writes to w, using the given options. If opts is nil, the default options are used.
func (*TextHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*TextHandler) Handle ¶
Handle formats its slog.Record argument as a single line of space-separated key=value items.
func (*TextHandler) WithAttrs ¶
func (h *TextHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a new TextHandler whose attributes consists of h's attributes followed by attrs.
func (*TextHandler) WithGroup ¶
func (h *TextHandler) WithGroup(name string) slog.Handler
WithGroup returns a new TextHandler with the given group appended to h's groups.