log

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Debug = "DEBUG"
	Info  = "INFO"
	Warn  = "WARN"
	Error = "ERROR"
)

Variables

This section is empty.

Functions

func SeverityToLevel

func SeverityToLevel(s string) (slog.Level, error)

Returns severity level based on string.

Types

type Logger

type Logger interface {
	// DebugContext is for reporting additional information about internal operations.
	DebugContext(ctx context.Context, format string, args ...any)
	// InfoContext is for reporting informational messages.
	InfoContext(ctx context.Context, format string, args ...any)
	// WarnContext is for reporting warning messages.
	WarnContext(ctx context.Context, format string, args ...any)
	// ErrorContext is for reporting errors.
	ErrorContext(ctx context.Context, format string, args ...any)
	// Single standard slog.Logger that routes records to the outLogger or
	// errLogger based on log levels
	SlogLogger() *slog.Logger
}

Logger is the interface used throughout the project for logging.

func NewLogger

func NewLogger(format, level string, out, err io.Writer) (Logger, error)

NewLogger creates a new logger based on the provided format and level.

func NewStdLogger

func NewStdLogger(outW, errW io.Writer, logLevel string) (Logger, error)

NewStdLogger create a Logger that uses out and err for informational and error messages.

func NewStructuredLogger

func NewStructuredLogger(outW, errW io.Writer, logLevel string) (Logger, error)

NewStructuredLogger create a Logger that logs messages using JSON.

type SplitHandler

type SplitHandler struct {
	OutHandler slog.Handler
	ErrHandler slog.Handler
}

func (*SplitHandler) Enabled

func (h *SplitHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SplitHandler) Handle

func (h *SplitHandler) Handle(ctx context.Context, r slog.Record) error

func (*SplitHandler) WithAttrs

func (h *SplitHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SplitHandler) WithGroup

func (h *SplitHandler) WithGroup(name string) slog.Handler

type StdLogger

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

StdLogger is the standard logger

func (*StdLogger) DebugContext

func (sl *StdLogger) DebugContext(ctx context.Context, msg string, keysAndValues ...any)

DebugContext logs debug messages

func (*StdLogger) ErrorContext

func (sl *StdLogger) ErrorContext(ctx context.Context, msg string, keysAndValues ...any)

ErrorContext logs error messages

func (*StdLogger) InfoContext

func (sl *StdLogger) InfoContext(ctx context.Context, msg string, keysAndValues ...any)

InfoContext logs debug messages

func (*StdLogger) SlogLogger

func (sl *StdLogger) SlogLogger() *slog.Logger

SlogLogger returns a single standard *slog.Logger that routes records to the outLogger or errLogger based on the log level.

func (*StdLogger) WarnContext

func (sl *StdLogger) WarnContext(ctx context.Context, msg string, keysAndValues ...any)

WarnContext logs warning messages

type StructuredLogger

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

func (*StructuredLogger) DebugContext

func (sl *StructuredLogger) DebugContext(ctx context.Context, msg string, keysAndValues ...any)

DebugContext logs debug messages

func (*StructuredLogger) ErrorContext

func (sl *StructuredLogger) ErrorContext(ctx context.Context, msg string, keysAndValues ...any)

ErrorContext logs error messages

func (*StructuredLogger) InfoContext

func (sl *StructuredLogger) InfoContext(ctx context.Context, msg string, keysAndValues ...any)

InfoContext logs info messages

func (*StructuredLogger) SlogLogger

func (sl *StructuredLogger) SlogLogger() *slog.Logger

SlogLogger returns a single standard *slog.Logger that routes records to the outLogger or errLogger based on the log level.

func (*StructuredLogger) WarnContext

func (sl *StructuredLogger) WarnContext(ctx context.Context, msg string, keysAndValues ...any)

WarnContext logs warning messages

type ValueTextHandler

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

ValueTextHandler is a [Handler] that writes Records to an io.Writer with values separated by spaces.

func NewValueTextHandler

func NewValueTextHandler(out io.Writer, opts *slog.HandlerOptions) *ValueTextHandler

NewValueTextHandler creates a ValueTextHandler that writes to out, using the given options.

func (*ValueTextHandler) Enabled

func (h *ValueTextHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*ValueTextHandler) Handle

func (h *ValueTextHandler) Handle(ctx context.Context, r slog.Record) error

Handle formats its argument [Record] as a single line of space-separated values. Example output format: 2024-11-12T15:08:11.451377-08:00 INFO "Initialized 0 sources.\n"

func (*ValueTextHandler) WithAttrs

func (h *ValueTextHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ValueTextHandler) WithGroup

func (h *ValueTextHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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