package memlogger
import "go.chromium.org/luci/common/logging/memlogger"
Index ¶
- func Dump(ctx context.Context, w io.Writer) (n int, err error)
- func MustDumpStdout(ctx context.Context)
- func Reset(ctx context.Context)
- func ShouldHaveLog(actual any, expected ...any) string
- func ShouldNotHaveLog(actual any, expected ...any) string
- func Use(ctx context.Context) context.Context
- type LogEntry
- type MemLogger
- func (m *MemLogger) Debugf(format string, args ...any)
- func (m *MemLogger) Dump(w io.Writer) (n int, err error)
- func (m *MemLogger) Errorf(format string, args ...any)
- func (m *MemLogger) Get(lvl logging.Level, msg string, data map[string]any) *LogEntry
- func (m *MemLogger) GetFunc(f func(*LogEntry) bool) *LogEntry
- func (m *MemLogger) Has(lvl logging.Level, msg string, data map[string]any) bool
- func (m *MemLogger) HasFunc(f func(*LogEntry) bool) bool
- func (m *MemLogger) Infof(format string, args ...any)
- func (m *MemLogger) LogCall(lvl logging.Level, calldepth int, format string, args []any)
- func (m *MemLogger) LogTo(log interface{ Logf(fmt string, args ...any) })
- func (m *MemLogger) Messages() []LogEntry
- func (m *MemLogger) Reset()
- func (m *MemLogger) Warningf(format string, args ...any)
Functions ¶
func Dump ¶
Dump is a convenience function to dump the current contents of the memory logger to the writer.
This will panic if the current logger is not a memory logger.
func MustDumpStdout ¶
MustDumpStdout is a convenience function to dump the current contents of the memory logger to stdout.
This will panic if the current logger is not a memory logger.
func Reset ¶
Reset is a convenience function to reset the current memory logger.
This will panic if the current logger is not a memory logger.
func ShouldHaveLog ¶
ShouldHaveLog is a goconvey custom assertion which asserts that the logger has received a log. It takes up to 3 arguments.
`actual` should either be a *MemLogger or a context.Context containing a *MemLogger.
argument 1 (expected[0]) is the log level. argument 2 (expected[1]) is a substring the message. If omitted or the empty string, this value is not checked. argument 3 (expected[2]) is the fields data. If omitted or nil, this value is not checked.
func ShouldNotHaveLog ¶
ShouldNotHaveLog is the inverse of ShouldHaveLog. It asserts that the logger has not seen such a log.
func Use ¶
Use adds a memory backed Logger to Context, with concrete type *MemLogger. Casting to the concrete type can be used to inspect the log output after running a test case, for example.
Types ¶
type LogEntry ¶
type LogEntry struct { Level logging.Level Msg string Data map[string]any StackTrace logging.StackTrace CallDepth int }
LogEntry is a single entry in a MemLogger, containing a message and a severity.
type MemLogger ¶
type MemLogger struct {
// contains filtered or unexported fields
}
MemLogger is an implementation of Logger. Zero value is a valid logger.
func (*MemLogger) Debugf ¶
Debugf implements the logging.Logger interface.
func (*MemLogger) Dump ¶
Dump dumps the current memory logger contents to the given writer in a human-readable format.
func (*MemLogger) Errorf ¶
Errorf implements the logging.Logger interface.
func (*MemLogger) Get ¶
Get returns the first matching log entry. Note that lvl, msg and data have to match the entry precisely.
func (*MemLogger) GetFunc ¶
GetFunc returns the first matching log entry.
func (*MemLogger) Has ¶
Has returns true iff the MemLogger contains the specified log message. Note that lvl, msg and data have to match the entry precisely.
func (*MemLogger) HasFunc ¶
HasFunc returns true iff the MemLogger contains a matching log message.
func (*MemLogger) Infof ¶
Infof implements the logging.Logger interface.
func (*MemLogger) LogCall ¶
LogCall implements the logging.Logger interface.
func (*MemLogger) LogTo ¶
LogTo writes each contained log to the given interface.
Designed to be used with a `testing.TB` implementation:
if !check.Loosely(t, ml.Messages(), should.BeEmpty) { ml.LogTo(t) t.Fail() }
This will also detect and call the `Helper()` method, if `log` defines it.
func (*MemLogger) Messages ¶
Messages returns all of the log messages that this memory logger has recorded.
func (*MemLogger) Reset ¶
func (m *MemLogger) Reset()
Reset resets the logged messages recorded so far.
func (*MemLogger) Warningf ¶
Warningf implements the logging.Logger interface.
Source Files ¶
assertions.go memory.go
- Version
- v0.0.0-20250617093544-e09c11da3c8c (latest)
- Published
- Jun 17, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 14 hours ago –
Tools for package owners.