Documentation
¶
Overview ¶
Package logbuf provides an in-memory ring buffer for structured log entries. It implements io.Writer for use with zerolog.MultiLevelWriter.
Index ¶
Constants ¶
const DefaultCapacity = 10000
DefaultCapacity is the default number of log entries the ring buffer holds.
Variables ¶
This section is empty.
Functions ¶
func EntryMatchesQuery ¶
EntryMatchesQuery returns true if any of the entry's text fields contain the query (case-insensitive).
func LevelAtLeast ¶
LevelAtLeast returns true if entryLevel is at least as severe as minLevel.
Types ¶
type LogEntry ¶
type LogEntry struct {
Timestamp int64 `json:"timestamp"`
Level string `json:"level"`
Message string `json:"message"`
Fields map[string]any `json:"fields,omitempty"`
Raw string `json:"raw"`
}
LogEntry represents a single structured log entry.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a thread-safe circular buffer of log entries with pub/sub support.
func NewRingBuffer ¶
func NewRingBuffer(capacity int) *RingBuffer
NewRingBuffer creates a new ring buffer with the given capacity. If capacity <= 0, DefaultCapacity is used.
func (*RingBuffer) Snapshot ¶
func (rb *RingBuffer) Snapshot(n int, minLevel string, query string) []LogEntry
Snapshot returns the last n entries, optionally filtered by minimum level and query string. If n <= 0 or n > available entries, all available entries are returned. Entries are returned in chronological order (oldest first).
func (*RingBuffer) Subscribe ¶
func (rb *RingBuffer) Subscribe() (chan LogEntry, func())
Subscribe returns a channel that receives new log entries and an unsubscribe function. The channel has a buffer of 64 entries; slow consumers will miss entries.