logrusr

package module
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 7 Imported by: 38

README

Logrusr

Go Reference GitHub Actions Coverage Status Go Report Card

A logr implementation using logrus.

Usage

import (
    "github.com/bombsimon/logrusr/v4"
    "github.com/go-logr/logr"
    "github.com/sirupsen/logrus"
)

func main() {
    logrusLog := logrus.New()
    log := logrusr.New(logrusLog)

    log = log.WithName("MyName").WithValues("user", "you")
    log.Info("Logr in action!", "the answer", 42)
}

For more details, see example.

Implementation details

The New method takes a logrus.FieldLogger interface as input which means this works with both logrus.Logger and logrus.Entry. This is currently a quite naive implementation in early state. Use with caution.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(l logrus.FieldLogger, opts ...Option) logr.Logger

New will return a new logr.Logger created from a logrus.FieldLogger.

Types

type FormatFunc

type FormatFunc func(interface{}) interface{}

FormatFunc is the function to format log values with for non primitive data. If this is not set (default) all unknown types will be JSON marshaled and added as a string.

type Option

type Option func(l *logrusr)

Option is options to give when construction a logrusr logger.

func WithFormatter

func WithFormatter(f FormatFunc) Option

WithFormatter will set the FormatFunc to use. If you only want to format a specific type that is yours, prefer using the logr.Marshaler interface instead. The `FormatFunc` is better suited for types that are not yours such as external types, maps or slices.

func WithName

func WithName(name ...string) Option

WithName will set an initial name instead of having to call `WithName` on the logger itself after constructing it.

func WithReportCaller

func WithReportCaller() Option

WithReportCaller will enable reporting of the caller.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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