level

package
v1.10.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package level is a thin compatibility wrapper that mimics common go-kit/log/level usage patterns while delegating to the Go standard library's log/slog package.

It enables transitional code like: level.Info(logger).Log("msg", "hello", "k", 1) to continue working while using slog levels and structured attributes under the hood.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Log(keyvals ...any) error
}

Logger is compatible with the minimal subset of the go-kit Logger interface that is used together with go-kit/log/level: a Log method accepting keyvals.

The Log method accepts alternating key/value pairs (like slog and go-kit). Non-string keys are ignored. If a key "msg" with a string value is present, it will be used as the record message; otherwise a level-specific default is used. The remaining pairs are emitted as structured attributes via slog. An odd trailing key without value is ignored.

Example:

level.Warn(slogLogger).Log("msg", "deprecated", "feature", "x")
level.Debug(slogLogger).Log("k", 1, "x", 2) // message defaults to "debug"

Note: The emitted level is provided by slog and shouldn't be redundantly stored as an attribute named "level".

This package is intended for migration only. Prefer direct slog use over time.

func Debug

func Debug(l *slog.Logger) Logger

Debug returns a Logger that logs at slog.LevelDebug.

func Error

func Error(l *slog.Logger) Logger

Error returns a Logger that logs at slog.LevelError.

func Info

func Info(l *slog.Logger) Logger

Info returns a Logger that logs at slog.LevelInfo.

func Warn

func Warn(l *slog.Logger) Logger

Warn returns a Logger that logs at slog.LevelWarn.

func WithContext

func WithContext(ctx context.Context, l *slog.Logger) Logger

WithContext allows attaching a context to the logger used for emission. The returned logger uses LevelInfo by default.

Jump to

Keyboard shortcuts

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