Skip to content

Commit

Permalink
Add Entries() to fetch all log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Oct 11, 2020
1 parent 8d5b2f4 commit 5319d9c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions testing/logger/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ import (

// LogCapture allows testing code to query log output.
type LogCapture struct {
mu sync.Mutex
// entries []*LogEntry
mu sync.Mutex
entries []string
}

//type LogEntry struct {
// Level zerolog.Level
// Msg string
//}

// NewLogCapture captures logs for querying.
func NewLogCapture() *LogCapture {
c := &LogCapture{
Expand All @@ -51,10 +45,6 @@ func (c *LogCapture) Run(e *zerolog.Event, level zerolog.Level, msg string) {
c.mu.Lock()
defer c.mu.Unlock()
c.entries = append(c.entries, msg)
// c.entries = append(c.entries, &LogEntry{
// Level: level,
// Msg: msg,
// })
e.Discard()
}

Expand All @@ -66,9 +56,11 @@ func (c *LogCapture) AssertHasEntry(t *testing.T, msg string) {
if c.entries[i] == msg {
return
}
// if c.entries[i].Msg == msg {
// return true
// }
}
assert.Fail(t, fmt.Sprintf("Missing log message %q", msg), strings.Join(c.entries, "\n"))
}

// Entries returns all log entries.
func (c *LogCapture) Entries() []string {
return c.entries
}

0 comments on commit 5319d9c

Please sign in to comment.