slogr

package module
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

README

Slogr

Slogr provides an implementation of logr interfaces backed by slog.

Usage example

slogLogger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{}))
var log logr.Logger = slogr.New(slogLogger)
log.Info("Access granted.", "user", "john.doe" )

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogSink

func NewLogSink(logger *slog.Logger) logr.LogSink

NewLogSink returns a new logr.LogSink backed by slog.

Types

type LogSink

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

LogSink is a logr.LogSink backed by slog.

func (*LogSink) Enabled

func (s *LogSink) Enabled(level int) bool

Enabled reports whether the backend logger is enabled at the specified level. The level value should be a compatible slog level value.(e.g. slog.LevelDebug)

func (*LogSink) Error

func (s *LogSink) Error(err error, msg string, keysAndValues ...interface{})

Error logs an error, with the given message and key/value pairs as context.

func (*LogSink) Info

func (s *LogSink) Info(level int, msg string, keysAndValues ...interface{})

Info implements logr.LogSink.

func (*LogSink) Init

func (s *LogSink) Init(info logr.RuntimeInfo)

Init doesn't do anything because slog.Logger doesn't expose a way to set the logr.RuntimeInfo.CallDepth.

func (*LogSink) WithCallDepth

func (s *LogSink) WithCallDepth(depth int) logr.LogSink

WithCallDepth returns the same logr.LogSink instance because slog.Logger doesn't support a configurable call depth.

func (LogSink) WithName

func (s LogSink) WithName(name string) logr.LogSink

WithName returns a new logr.LogSink that starts a group having the given name. The keys of all attributes added to the new logr.LogSink will be qualified by the given name. (How that qualification happens depends on the [Handler.WithGroup] method of the logr.LogSink's Handler.)

func (LogSink) WithValues

func (s LogSink) WithValues(keysAndValues ...interface{}) logr.LogSink

WithValues returns a new logr.LogSink with additional key/value pairs set.

type Logger

type Logger = logr.Logger

Logger is an alias of logr.Logger.

func New

func New(logger *slog.Logger) Logger

New returns a new logr.Logger backed by slog.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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