testlog

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT, LGPL-3.0 Imports: 10 Imported by: 3

README

testlog

github.com/ethereum/go-ethereum/internal/testlog: a Go-ethereum util for logging in tests.

Since we use the same logging, but as an external package, we have to move the test utility to our own internal package.

This fork also made minor modifications:

  • Enable color by default.
  • Add estimateInfoLen and use this for message padding in flush() to align the contents of the log entries, compensating for the different lengths of the log decoration that the Go library adds.

Documentation

Overview

Package testlog provides a log handler for unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(t Testing, level slog.Level) log.Logger

Logger returns a logger which logs to the unit test log of t.

func LoggerWithHandlerMod added in v1.5.1

func LoggerWithHandlerMod(t Testing, level slog.Level, handlerMod func(slog.Handler) slog.Handler) log.Logger

Types

type CapturingHandler

type CapturingHandler struct {
	Logs *[]*slog.Record // shared among derived CapturingHandlers
	// contains filtered or unexported fields
}

CapturingHandler provides a log handler that captures all log records and optionally forwards them to a delegate. Note that it is not thread safe.

func CaptureLogger added in v1.5.1

func CaptureLogger(t Testing, level slog.Level) (_ log.Logger, ch *CapturingHandler)

func (*CapturingHandler) Clear

func (c *CapturingHandler) Clear()

func (*CapturingHandler) Enabled added in v1.5.1

func (*CapturingHandler) FindLog

func (c *CapturingHandler) FindLog(filters ...LogFilter) *HelperRecord

func (*CapturingHandler) FindLogs added in v1.6.1

func (c *CapturingHandler) FindLogs(filters ...LogFilter) []*HelperRecord

func (*CapturingHandler) Handle added in v1.5.1

func (c *CapturingHandler) Handle(ctx context.Context, r slog.Record) error

func (*CapturingHandler) WithAttrs added in v1.5.1

func (c *CapturingHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*CapturingHandler) WithGroup added in v1.5.1

func (c *CapturingHandler) WithGroup(name string) slog.Handler

type HelperRecord

type HelperRecord struct {
	*slog.Record
}

func (HelperRecord) AttrValue added in v1.5.1

func (h HelperRecord) AttrValue(name string) (v any)

type LogFilter added in v1.6.1

type LogFilter func(*slog.Record) bool

func NewAttributesContainsFilter added in v1.7.2

func NewAttributesContainsFilter(key, value string) LogFilter

func NewAttributesFilter added in v1.7.2

func NewAttributesFilter(key, value string) LogFilter

func NewLevelFilter added in v1.6.1

func NewLevelFilter(level slog.Level) LogFilter

func NewMessageContainsFilter added in v1.6.1

func NewMessageContainsFilter(message string) LogFilter

func NewMessageFilter added in v1.6.1

func NewMessageFilter(message string) LogFilter

type Testing

type Testing interface {
	Logf(format string, args ...any)
	Helper()
}

Testing interface to log to. Some functions are marked as Helper function to log the call site accurately. Standard Go testing.TB implements this, as well as Hive and other Go-like test frameworks.

Jump to

Keyboard shortcuts

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