Debian Codegraph @

handlers/memory/memory.go

raw
1 // Package memory implements an in-memory handler useful for testing, as the
2 // entries can be accessed after writes.
3 package memory
4
5 import (
6 "sync"
7
8 "github.com/bep/logg"
9 )
10
11 // Handler implementation.
12 type Handler struct {
13 mu sync.Mutex
14 Entries []*logg.Entry
15 }
16
17 // New handler.
18 func New() *Handler {
19 return &Handler{}
20 }
21
22 // HandleLog implements logg.Handler.
23 func (h *Handler) HandleLog(e *logg.Entry) error {
24 h.mu.Lock()
25 defer h.mu.Unlock()
26 h.Entries = append(h.Entries, e.Clone())
27 return nil
28 }