Skip to content

A logr LogSink implementation using bytes.Buffer

License

Notifications You must be signed in to change notification settings

tonglil/buflogr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

May 28, 2024
201c39f · May 28, 2024

History

23 Commits
Dec 7, 2023
Mar 4, 2022
Jan 13, 2022
May 17, 2022
Mar 4, 2022
May 28, 2024
May 28, 2024

Repository files navigation

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.