logger

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelTrace = slog.Level(-8)
	LevelFatal = slog.Level(12)
	LevelPanic = slog.Level(13)
)

Variables

View Source
var LevelNames = map[slog.Leveler]string{
	LevelTrace: "TRACE",
	LevelFatal: "FATAL",
	LevelPanic: "PANIC",
}

Functions

func ReplaceAttr

func ReplaceAttr(_ []string, attr slog.Attr) slog.Attr

ReplaceAttr normalizes custom levels before the handler encodes them.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger manages logging operations with various log levels and modes.

func New

func New(calldepth int, _ []uintptr, levels ...*slog.LevelVar) *Logger

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

func NewWithOptions(opts ...Option) *Logger

NewWithOptions creates a new Logger instance using functional options.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs a debug-level message with optional arguments.

func (*Logger) DebugContext

func (l *Logger) DebugContext(ctx context.Context, msg string, args ...interface{})

DebugContext logs a debug-level message with optional arguments and context.

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

Error logs an error-level message with optional arguments.

func (*Logger) ErrorContext

func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)

ErrorContext logs an error-level message with optional arguments and context.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...any)

Fatal logs a fatal-level message, then exits the application.

func (*Logger) FatalContext

func (l *Logger) FatalContext(ctx context.Context, msg string, args ...any)

FatalContext logs a fatal-level message with context, then exits the application.

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs an info-level message with optional arguments.

func (*Logger) InfoContext

func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)

InfoContext logs an info-level message with context and optional arguments.

func (*Logger) Panic

func (l *Logger) Panic(msg string, args ...any)

Panic logs a panic-level message, then panics with the message.

func (*Logger) PanicContext

func (l *Logger) PanicContext(ctx context.Context, msg string, args ...any)

PanicContext logs a panic-level message with context, then panics with the message.

func (*Logger) Print

func (l *Logger) Print(msg string, args ...any)

Print logs a trace-level message with optional arguments.

func (*Logger) PrintContext

func (l *Logger) PrintContext(ctx context.Context, msg string, args ...any)

PrintContext logs a trace-level message with context and optional arguments.

func (*Logger) SetCalldepth

func (l *Logger) SetCalldepth(calldepth int)

SetCalldepth configures the number of stack frames to ascend for logging.

func (*Logger) SetDebugStackTrace added in v1.4.0

func (l *Logger) SetDebugStackTrace(enabled bool)

SetDebugStackTrace controls whether debug logs include a stack trace.

func (*Logger) SetJSONHandler added in v1.4.0

func (l *Logger) SetJSONHandler(w io.Writer)

SetJSONHandler configures the logger to emit JSON logs to the provided writer.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level slog.Level) (oldLevel slog.Level)

SetLevel sets the logging level for the Logger instance and returns the previous level.

func (*Logger) SetSource added in v1.4.0

func (l *Logger) SetSource(enabled bool)

SetSource controls whether source metadata is attached to log records.

func (*Logger) SetTextHandler added in v1.4.0

func (l *Logger) SetTextHandler(w io.Writer)

SetTextHandler configures the logger to emit text logs to the provided writer.

func (*Logger) StackTrace

func (l *Logger) StackTrace() slog.Attr

StackTrace provides a stack trace of up to 10 layers from where the error or incident was generated.

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs a warning-level message with optional arguments.

func (*Logger) WarnContext

func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)

WarnContext logs a warning-level message with optional arguments and context.

type Option added in v1.4.0

type Option func(*Logger)

Option configures a Logger instance.

func WithDebugStackTrace added in v1.4.0

func WithDebugStackTrace(enabled bool) Option

WithDebugStackTrace controls whether debug logs include a stack trace.

func WithJSONHandler added in v1.4.0

func WithJSONHandler(w io.Writer) Option

WithJSONHandler configures a JSON handler that writes to w.

func WithLevel added in v1.4.0

func WithLevel(level slog.Level) Option

WithLevel sets the initial logging level.

func WithSource added in v1.4.0

func WithSource(enabled bool) Option

WithSource controls whether source metadata is attached to log records.

func WithTextHandler added in v1.4.0

func WithTextHandler(w io.Writer) Option

WithTextHandler configures a text handler that writes to w.

type Priority deprecated

type Priority int8

Priority represents the level of importance for log messages. Higher values indicate greater importance.

Deprecated: use slog.Level instead.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL