testlog

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT, LGPL-3.0, MIT Imports: 6 Imported by: 1

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 Handler

func Handler(t Testing, level log.Lvl) log.Handler

Handler returns a log handler which logs to the unit test log of t.

func Logger

func Logger(t Testing, level log.Lvl) log.Logger

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

Types

type CapturingHandler added in v1.1.2

type CapturingHandler struct {
	Delegate log.Handler
	Logs     []*log.Record
}

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 (*CapturingHandler) Clear added in v1.1.2

func (c *CapturingHandler) Clear()

func (*CapturingHandler) FindLog added in v1.1.2

func (c *CapturingHandler) FindLog(lvl log.Lvl, msg string) *HelperRecord

func (*CapturingHandler) Log added in v1.1.2

func (c *CapturingHandler) Log(r *log.Record) error

type HelperRecord added in v1.1.2

type HelperRecord struct {
	*log.Record
}

func (*HelperRecord) GetContextValue added in v1.1.2

func (h *HelperRecord) GetContextValue(name string) any

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