photoprism/internal/event/buffer.go
Michael Mayer 2de1e338bd Logs: Prevent feedback loops by omitting repeated messages #2335
This also prevents debug and trace messages to be sent to the frontend.
2022-05-20 11:31:39 +02:00

28 lines
472 B
Go

package event
import (
"bytes"
"sync"
)
// Buffer is a goroutine safe buffer.
type Buffer struct {
buffer bytes.Buffer
mutex sync.RWMutex
}
// Set updates the buffer content.
func (b *Buffer) Set(s string) (err error) {
b.mutex.Lock()
defer b.mutex.Unlock()
b.buffer.Reset()
_, err = b.buffer.WriteString(s)
return err
}
// Get returns the buffer content.
func (b *Buffer) Get() string {
b.mutex.RLock()
defer b.mutex.RUnlock()
return b.buffer.String()
}