Documentation
¶
Overview ¶
Package bufferadapter provides an in-memory logger adapter for testing.
This package implements the logger.Adapter interface by storing log entries in memory, allowing tests to inspect what was logged. The adapter is safe for concurrent use and designed specifically for testing purposes.
Usage ¶
Create a buffer adapter and use it with a logger:
adapter, buff := bufferadapter.New()
log := logger.New(adapter, logger.LevelInfo)
log.Info("test message", fields.F("key", "value"))
// Assert in tests
entries := buff.GetAll()
require.Len(t, entries, 1)
assert.Equal(t, "test message", entries[0].Msg)
assert.Equal(t, logger.LevelInfo, entries[0].Level)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New() (*Adapter, *LogEntries)
New creates a new Adapter instance along with a new LogEntries buffer that will be used by adapter.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is a logger.Adapter implementation that writes logs to the provided LogEntries collection.
type LogEntries ¶
type LogEntries struct {
// contains filtered or unexported fields
}
LogEntries is a buffer for storing log entries in memory. It is safe for concurrent use.
func (*LogEntries) Add ¶ added in v0.8.0
func (le *LogEntries) Add(entry LogEntry)
Add appends a log entry.
func (*LogEntries) Get ¶ added in v0.8.0
func (le *LogEntries) Get(i int) LogEntry
Get returns a copy of the log entry at the given index. Panics if index is out of range.
func (*LogEntries) GetAll ¶ added in v0.8.0
func (le *LogEntries) GetAll() []LogEntry
GetAll returns a copy of log entries buffer.
func (*LogEntries) Len ¶ added in v0.8.0
func (le *LogEntries) Len() int
Len returns the number of log entries.
func (*LogEntries) Reset ¶
func (le *LogEntries) Reset()
Reset clears all log entries, preserving capacity.