buflogr

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 3

README

buflogr

Go Reference

Go Report Card

A logr LogSink implementation using bytes.Buffer.

Usage

import (
	"bytes"
	"fmt"

	"github.com/go-logr/logr"
	"github.com/tonglil/buflogr"
)

func main() {
	var buf bytes.Buffer
	var log logr.Logger = buflogr.NewWithBuffer(&buf)

	log = log.WithName("my app")
	log = log.WithValues("format", "none")

	log.Info("Logr in action!", "the answer", 42)

	fmt.Print(buf.String())
}

Implementation Details

This is a simple log adapter to log messages into a buffer. Useful for testing.

Documentation

Index

Constants

View Source
const (
	LevelError = "ERROR"
	LevelInfo  = "INFO"
	LevelV     = "V[%d]"
)

Variables

View Source
var (
	// NameSeparator separates names for logr.WithName.
	NameSeparator = "/"
	// KVFormatter is a function that renders a slice of key/value pairs into a
	// string with the signature: `func(kv ...interface{}) string`.
	KVFormatter = defaultKVFormatter
)

Functions

func New

func New() logr.Logger

New returns a logr.Logger with logr.LogSink implemented by bufLogger using a new bytes.Buffer.

func NewWithBuffer

func NewWithBuffer(b *bytes.Buffer) logr.Logger

New returns a logr.Logger with logr.LogSink implemented by bufLogger with an existing bytes.Buffer.

Types

type Underlier

type Underlier interface {
	GetUnderlying() *bufLogger
}

Underlier exposes access to the underlying testing.T instance. Since callers only have a logr.Logger, they have to know which implementation is in use, so this interface is less of an abstraction and more of a way to test type conversion.

Jump to

Keyboard shortcuts

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