logcollect

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: May 12, 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) SnapshotFiltered added in v0.3.0

func (c *Collector) SnapshotFiltered(processID string, stream uint8, since time.Time, lines int) []byte

SnapshotFiltered returns bytes from chunks whose timestamp is at or after `since` (zero time disables the filter). If `lines > 0`, only the trailing N newline-delimited lines are returned. Backs `cliwrap logs --since` and `--lines`.

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 FileSink added in v0.3.0

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

FileSink persists LogEntries to disk via per-(process, stream) FileRotators. Each rotator's basename is "<processID>.<stream>" so log files are easy to inspect with the standard tail/grep toolchain. FileSink is safe for concurrent use (the protecting mutex serializes Write across all rotators).

FileSink implements Sink and is intended to be passed to CollectorOptions.ExtraSinks alongside the in-memory RingBufferSink so the same chunk reaches both the live snapshot API and durable storage.

func NewFileSink added in v0.3.0

func NewFileSink(opts FileSinkOptions) *FileSink

NewFileSink returns a sink that lazily opens per-stream rotators in opts.Dir.

func (*FileSink) Close added in v0.3.0

func (s *FileSink) Close() error

Close closes every rotator. Subsequent Writes return an error from the closed rotator. Idempotent: subsequent Closes return nil from each already-closed rotator.

func (*FileSink) Flush added in v0.3.0

func (s *FileSink) Flush() error

Flush is a no-op: FileRotator writes directly to the OS via the open file descriptor, so each Write returning success means the byte is in the kernel page cache. (We deliberately don't fsync per chunk — that would dominate the IPC budget under a chatty child.)

func (*FileSink) Write added in v0.3.0

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

Write appends e.Data to the rotator for (e.ProcessID, e.Stream). Empty data is a no-op. Disk-full / permission errors propagate.

type FileSinkOptions added in v0.3.0

type FileSinkOptions struct {
	// Dir is the directory under which per-(process, stream) log files
	// are created. The directory is created with mode 0700 lazily.
	Dir string
	// MaxSize and MaxFiles are forwarded to each backing FileRotator.
	// Zero values fall back to FileRotator defaults (64 MiB, 7 files).
	MaxSize  int64
	MaxFiles int
}

FileSinkOptions configures a FileSink.

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 chunkBuffers. Each chunk retains its arrival timestamp so SnapshotFiltered can serve --since.

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) SnapshotFiltered added in v0.3.0

func (s *RingBufferSink) SnapshotFiltered(processID string, stream uint8, since time.Time, lines int) []byte

SnapshotFiltered returns bytes from chunks with Ts >= since (zero = no filter); if lines > 0, returns only the trailing N newline-delimited lines. Returns nil if no buffer exists or no chunks pass the filter.

func (*RingBufferSink) Write

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

Write routes e to the appropriate 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