logcollect

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector is the top-level log ingestion entry point. It routes writes to an embedded RingBufferSink plus any extra sinks the caller provides.

func NewCollector

func NewCollector(opts CollectorOptions) *Collector

NewCollector returns a Collector with the given capacity per stream.

func (*Collector) Close

func (c *Collector) Close()

Close releases resources.

func (*Collector) Snapshot

func (c *Collector) Snapshot(processID string, stream uint8) []byte

Snapshot returns the ring buffer for (processID, stream).

func (*Collector) Write

func (c *Collector) Write(e LogEntry)

Write ingests a log entry.

type CollectorOptions

type CollectorOptions struct {
	RingBufferBytes int
	ExtraSinks      []Sink
}

CollectorOptions configures the LogCollector.

type FileRotator

type FileRotator struct {
	// contains filtered or unexported fields
}

FileRotator writes to an active log file and rotates it when the size cap is exceeded. Rotated files are named "<base>.<n>.log" for n = 1..MaxFiles-1.

func NewFileRotator

func NewFileRotator(opts RotatorOptions) (*FileRotator, error)

NewFileRotator opens (creating if necessary) the active log file.

func (*FileRotator) Close

func (r *FileRotator) Close() error

Close flushes and closes the active file.

func (*FileRotator) Write

func (r *FileRotator) Write(p []byte) (int, error)

Write appends data, rotating if needed.

type LogEntry

type LogEntry struct {
	ProcessID string
	Stream    uint8 // 0=stdout, 1=stderr, 2=diag
	SeqNo     uint64
	Timestamp time.Time
	Data      []byte
}

LogEntry is one logical chunk of log data delivered to a Sink.

type RingBuffer

type RingBuffer struct {
	// contains filtered or unexported fields
}

RingBuffer is a byte-oriented circular buffer with FIFO eviction. All methods are safe for concurrent use.

func NewRingBuffer

func NewRingBuffer(capacity int) *RingBuffer

NewRingBuffer returns a ring buffer with the given byte capacity.

func (*RingBuffer) Size

func (r *RingBuffer) Size() int

Size returns the number of bytes currently buffered.

func (*RingBuffer) Snapshot

func (r *RingBuffer) Snapshot() []byte

Snapshot returns a copy of the currently buffered bytes in FIFO order.

func (*RingBuffer) Write

func (r *RingBuffer) Write(p []byte) (int, error)

Write appends p to the buffer, evicting old bytes if necessary. It always returns len(p), nil to satisfy io.Writer.

type RingBufferSink

type RingBufferSink struct {
	// contains filtered or unexported fields
}

RingBufferSink stores data per (process, stream) in RingBuffers.

func NewRingBufferSink

func NewRingBufferSink(capacity int) *RingBufferSink

NewRingBufferSink returns a sink whose buffers have the given byte capacity.

func (*RingBufferSink) Close

func (s *RingBufferSink) Close() error

func (*RingBufferSink) Flush

func (s *RingBufferSink) Flush() error

func (*RingBufferSink) Snapshot

func (s *RingBufferSink) Snapshot(processID string, stream uint8) []byte

Snapshot returns the current contents for (processID, stream) or nil.

func (*RingBufferSink) Write

func (s *RingBufferSink) Write(e LogEntry) error

Write routes e to the appropriate ring buffer.

type RotatorOptions

type RotatorOptions struct {
	Dir      string
	BaseName string
	MaxSize  int64 // rotate when current file exceeds this many bytes
	MaxFiles int   // keep at most this many files (including current)
}

RotatorOptions configures a FileRotator.

type Sink

type Sink interface {
	Write(entry LogEntry) error
	Flush() error
	Close() error
}

Sink is a consumer of LogEntry values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL