subtree(3p/gerrit-queue): Vendor at commit '24f5a642'

Imported from github/tvlfyi/gerrit-queue, originally from
github/tweag/gerrit-queue but that upstream is unmaintained.

git-subtree-dir: third_party/gerrit-queue
git-subtree-mainline: ff10b7ab83
git-subtree-split: 24f5a642af
Change-Id: I307cc38185ab9e25eb102c95096298a150ae13a2
This commit is contained in:
Vincent Ambo 2021-12-09 16:11:32 +03:00
commit 59f97332b3
21 changed files with 1641 additions and 0 deletions

View file

@ -0,0 +1,34 @@
package misc
import (
"sync"
"github.com/apex/log"
)
// RotatingLogHandler implementation.
type RotatingLogHandler struct {
mu sync.Mutex
Entries []*log.Entry
maxEntries int
}
// NewRotatingLogHandler creates a new rotating log handler
func NewRotatingLogHandler(maxEntries int) *RotatingLogHandler {
return &RotatingLogHandler{
maxEntries: maxEntries,
}
}
// HandleLog implements log.Handler.
func (h *RotatingLogHandler) HandleLog(e *log.Entry) error {
h.mu.Lock()
defer h.mu.Unlock()
// drop tail if we have more entries than maxEntries
if len(h.Entries) > h.maxEntries {
h.Entries = append([]*log.Entry{e}, h.Entries[:(h.maxEntries-2)]...)
} else {
h.Entries = append([]*log.Entry{e}, h.Entries...)
}
return nil
}