logrus

package module
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 5 Imported by: 0

README

slog.Logger adapter for logrus

Go Reference

This package implements a wrapper around a *logrus.Logger so it can be used as a slog.Logger.

It is important SetReportCaller() is disabled otherwise logrus will set a useless "method" field pointing to our Print() handler. WithStack() will set the "method" field considering the provided skip value

WithStack() will also create a "call-stack" field with the complete call stack from the caller upward.

See also

Documentation

Overview

Package logrus provides a slog.Logger using github.com/sirupsen/logrus Logger as backend

Index

Constants

View Source
const (
	// CallerFieldName is the field name to be used by WithStack()
	// attempting to mimick the effect of logrus' own SetReportCaller()
	CallerFieldName = "method"

	// StackFieldName is the field name used to store the formatted callstack
	StackFieldName = "call-stack"
)

Variables

This section is empty.

Functions

func New

func New(logger *logrus.Logger) slog.Logger

New creates a slog.Logger adaptor using a logrus as backend

Types

type Logger

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

Logger is an adaptor for using github.com/sirupsen/logrus as slog.Logger

func (*Logger) Debug

func (rl *Logger) Debug() slog.Logger

Debug returns a new logger set to add entries as level Debug

func (*Logger) Enabled

func (rl *Logger) Enabled() bool

Enabled tells if the logger is enabled

func (*Logger) Error

func (rl *Logger) Error() slog.Logger

Error returns a new logger set to add entries as level Error

func (*Logger) Fatal

func (rl *Logger) Fatal() slog.Logger

Fatal returns a new logger set to add entries as level Fatal

func (*Logger) Info

func (rl *Logger) Info() slog.Logger

Info returns a new logger set to add entries as level Info

func (*Logger) Panic

func (rl *Logger) Panic() slog.Logger

Panic returns a new logger set to add entries as level Panic

func (*Logger) Print

func (rl *Logger) Print(args ...any)

Print adds a log entry with arguments handled in the manner of fmt.Print

func (*Logger) Printf

func (rl *Logger) Printf(format string, args ...any)

Printf adds a log entry with arguments handled in the manner of fmt.Printf

func (*Logger) Println

func (rl *Logger) Println(args ...any)

Println adds a log entry with arguments handled in the manner of fmt.Println

func (*Logger) Warn

func (rl *Logger) Warn() slog.Logger

Warn returns a new logger set to add entries as level Warn

func (*Logger) WithEnabled

func (rl *Logger) WithEnabled() (slog.Logger, bool)

WithEnabled tells if the logger would log or not

func (*Logger) WithField

func (rl *Logger) WithField(label string, value any) slog.Logger

WithField adds a field to the log entry

func (*Logger) WithFields

func (rl *Logger) WithFields(fields map[string]any) slog.Logger

WithFields adds fields to the log entry

func (*Logger) WithLevel

func (rl *Logger) WithLevel(level slog.LogLevel) slog.Logger

WithLevel returns a new logger set to add entries to the specified level

func (*Logger) WithStack

func (rl *Logger) WithStack(skip int) slog.Logger

WithStack attaches a call stack to the log entry

Jump to

Keyboard shortcuts

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