Documentation
¶
Index ¶
- Constants
- Variables
- func ReplaceAttr(_ []string, attr slog.Attr) slog.Attr
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugContext(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Fatal(msg string, args ...any)
- func (l *Logger) FatalContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Panic(msg string, args ...any)
- func (l *Logger) PanicContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Print(msg string, args ...any)
- func (l *Logger) PrintContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) SetCalldepth(calldepth int)
- func (l *Logger) SetDebugStackTrace(enabled bool)
- func (l *Logger) SetJSONHandler(w io.Writer)
- func (l *Logger) SetLevel(level slog.Level) (oldLevel slog.Level)
- func (l *Logger) SetSource(enabled bool)
- func (l *Logger) SetTextHandler(w io.Writer)
- func (l *Logger) StackTrace() slog.Attr
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)
- type Option
- type Prioritydeprecated
Constants ¶
Variables ¶
var LevelNames = map[slog.Leveler]string{ LevelTrace: "TRACE", LevelFatal: "FATAL", LevelPanic: "PANIC", }
Functions ¶
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger manages logging operations with various log levels and modes.
func New ¶
New creates and initializes a new Logger instance. calldepth: Number of stack frames to ascend for log entries. pc: Deprecated and ignored. Kept for backward compatibility.
func NewWithOptions ¶ added in v1.4.0
NewWithOptions creates a new Logger instance using functional options.
func (*Logger) DebugContext ¶
DebugContext logs a debug-level message with optional arguments and context.
func (*Logger) ErrorContext ¶
ErrorContext logs an error-level message with optional arguments and context.
func (*Logger) FatalContext ¶
FatalContext logs a fatal-level message with context, then exits the application.
func (*Logger) InfoContext ¶
InfoContext logs an info-level message with context and optional arguments.
func (*Logger) PanicContext ¶
PanicContext logs a panic-level message with context, then panics with the message.
func (*Logger) PrintContext ¶
PrintContext logs a trace-level message with context and optional arguments.
func (*Logger) SetCalldepth ¶
SetCalldepth configures the number of stack frames to ascend for logging.
func (*Logger) SetDebugStackTrace ¶ added in v1.4.0
SetDebugStackTrace controls whether debug logs include a stack trace.
func (*Logger) SetJSONHandler ¶ added in v1.4.0
SetJSONHandler configures the logger to emit JSON logs to the provided writer.
func (*Logger) SetLevel ¶
SetLevel sets the logging level for the Logger instance and returns the previous level.
func (*Logger) SetSource ¶ added in v1.4.0
SetSource controls whether source metadata is attached to log records.
func (*Logger) SetTextHandler ¶ added in v1.4.0
SetTextHandler configures the logger to emit text logs to the provided writer.
func (*Logger) StackTrace ¶
StackTrace provides a stack trace of up to 10 layers from where the error or incident was generated.
type Option ¶ added in v1.4.0
type Option func(*Logger)
Option configures a Logger instance.
func WithDebugStackTrace ¶ added in v1.4.0
WithDebugStackTrace controls whether debug logs include a stack trace.
func WithJSONHandler ¶ added in v1.4.0
WithJSONHandler configures a JSON handler that writes to w.
func WithSource ¶ added in v1.4.0
WithSource controls whether source metadata is attached to log records.
func WithTextHandler ¶ added in v1.4.0
WithTextHandler configures a text handler that writes to w.