slogext

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: LGPL-3.0 Imports: 7 Imported by: 0

README

slogext

Small wrapper around the slog package primarily for CLIs.

Usage

Testing

A testing logger is provided as slogext.NewTestLogger. It automatically logs with test specific information.

Capturing Output for Testing

See captuered.go

Documentation

See our go docs (pkg.go.dev)

License

LGPL-3.0

Documentation

Overview

Package slogext is a small wrapper around the log/slog package focused on providing consistency in logging across the stencil codebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level = charmlog.Level

Level is a logging level.

const (
	// DebugLevel is for debug level logs.
	DebugLevel Level = charmlog.DebugLevel

	// InfoLevel is for info level logs.
	InfoLevel Level = charmlog.InfoLevel

	// WarnLevel is for warn level logs.
	WarnLevel Level = charmlog.WarnLevel

	// ErrorLevel is for error level logs
	ErrorLevel Level = charmlog.ErrorLevel

	// FatalLevel is for fatal level logs.
	FatalLevel Level = charmlog.FatalLevel
)

Contains valid Level values.

type Logger

type Logger interface {
	Info(string, ...any)
	Infof(string, ...any)
	Debug(string, ...any)
	Debugf(string, ...any)
	Error(string, ...any)
	Errorf(string, ...any)
	Warn(string, ...any)
	Warnf(string, ...any)
	With(...any) Logger
	WithError(error) Logger
	SetLevel(charmlog.Level)
	GetHandler() slog.Handler
}

Logger is a slog.Logger interface with extra functionality.

func New

func New() Logger

New creates a new Logger using the slog package.

func NewCapturedLogger

func NewCapturedLogger() (Logger, *bytes.Buffer)

NewCapturedLogger returns a Logger who's output is captured for future usage.

func NewNullLogger

func NewNullLogger() Logger

NewNullLogger returns a Logger that does not output anywhere.

func NewTestLogger

func NewTestLogger(t *testing.T) Logger

NewTestLogger creates a new logger for testing purposes. The logging level is set to DebugLevel to ensure all logs are captured.

func NewWithHandler

func NewWithHandler(h slog.Handler) Logger

NewWithHandler creates a new Logger using the slog package. Levels do not work since it is not a slog native concept.

func NewWithWriter

func NewWithWriter(w io.Writer) Logger

NewWithWriter creates a new Logger using the slog package with a custom writer target.

Jump to

Keyboard shortcuts

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