logtest

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Log Test

PkgGoDev

Documentation

Overview

Package logtest is a testing helper package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertRecordEqual added in v0.4.0

func AssertRecordEqual(t testing.TB, want, got log.Record) bool

AssertRecordEqual compares two log records, and fails the test if they are not equal.

Types

type EmittedRecord added in v0.4.0

type EmittedRecord struct {
	log.Record
	// contains filtered or unexported fields
}

EmittedRecord holds a log record the instrumentation received, alongside its context.

func (EmittedRecord) Context added in v0.4.0

func (rwc EmittedRecord) Context() context.Context

Context provides the context emitted with the record.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures a Recorder.

func WithEnabledFunc

func WithEnabledFunc(fn func(context.Context, log.EnabledParameters) bool) Option

WithEnabledFunc allows configuring whether the Recorder is enabled for specific log entries or not.

By default, the Recorder is enabled for every log entry.

type RecordFactory

type RecordFactory struct {
	Timestamp         time.Time
	ObservedTimestamp time.Time
	Severity          log.Severity
	SeverityText      string
	Body              log.Value
	Attributes        []log.KeyValue
}

RecordFactory is used to facilitate unit testing bridge implementations that make use of a go.opentelemetry.io/otel/log.Record

Do not use RecordFactory to create records in production code.

func (RecordFactory) NewRecord

func (b RecordFactory) NewRecord() log.Record

NewRecord returns a log record.

type Recorder

type Recorder struct {
	embedded.LoggerProvider
	// contains filtered or unexported fields
}

Recorder is a recorder that stores all received log records in-memory.

func NewRecorder

func NewRecorder(options ...Option) *Recorder

NewRecorder returns a new Recorder.

func (*Recorder) Logger

func (r *Recorder) Logger(name string, opts ...log.LoggerOption) log.Logger

Logger returns a copy of Recorder as a log.Logger with the provided scope information.

func (*Recorder) Reset

func (r *Recorder) Reset()

Reset clears the in-memory log records for all loggers.

func (*Recorder) Result

func (r *Recorder) Result() []*ScopeRecords

Result returns the current in-memory recorder log records.

type ScopeRecords

type ScopeRecords struct {
	// Name is the name of the instrumentation scope.
	Name string
	// Version is the version of the instrumentation scope.
	Version string
	// SchemaURL of the telemetry emitted by the scope.
	SchemaURL string
	// Attributes of the telemetry emitted by the scope.
	Attributes attribute.Set

	// Records are the log records, and their associated context this
	// instrumentation scope recorded.
	Records []EmittedRecord
}

ScopeRecords represents the records for a single instrumentation scope.

Jump to

Keyboard shortcuts

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