logtesting

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogEntry

type LogEntry struct {
	Level         string
	Message       string
	KeysAndValues []any
	Attrs         map[string]any
	Group         string
}

LogEntry represents a single log entry

type MockLogger

type MockLogger struct {
	Entries []LogEntry
	// contains filtered or unexported fields
}

MockLogger is a logger implementation that captures log calls for testing

func New

func New() *MockLogger

New creates a new MockLogger

func (*MockLogger) CountEntries

func (m *MockLogger) CountEntries(level string) int

CountEntries returns the number of log entries with the given level

func (*MockLogger) Debug

func (m *MockLogger) Debug(msg string, keysAndValues ...any)

func (*MockLogger) Error

func (m *MockLogger) Error(msg string, keysAndValues ...any)

func (*MockLogger) Fatal added in v0.2.0

func (m *MockLogger) Fatal(msg string, keysAndValues ...any)

func (*MockLogger) GetEntries

func (m *MockLogger) GetEntries() []LogEntry

GetEntries returns a copy of all log entries (thread-safe)

func (*MockLogger) HasEntry

func (m *MockLogger) HasEntry(level, message string) bool

HasEntry checks if an entry with the given level and message exists

func (*MockLogger) Info

func (m *MockLogger) Info(msg string, keysAndValues ...any)

func (*MockLogger) LastEntry

func (m *MockLogger) LastEntry() *LogEntry

LastEntry returns the last log entry, or nil if no entries

func (*MockLogger) Reset

func (m *MockLogger) Reset()

Reset clears all captured log entries

func (*MockLogger) String

func (m *MockLogger) String() string

String returns a human-readable representation of all log entries

func (*MockLogger) Trace

func (m *MockLogger) Trace(msg string, keysAndValues ...any)

func (*MockLogger) Warn

func (m *MockLogger) Warn(msg string, keysAndValues ...any)

func (*MockLogger) With

func (m *MockLogger) With(key string, value any) logger.Logger

func (*MockLogger) WithError

func (m *MockLogger) WithError(err error) logger.Logger

func (*MockLogger) WithGroup

func (m *MockLogger) WithGroup(group string) logger.Logger

Jump to

Keyboard shortcuts

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