Documentation
¶
Index ¶
- type Collector
- type CollectorOptions
- type FileRotator
- type FileSink
- type FileSinkOptions
- type LogEntry
- type RingBuffer
- type RingBufferSink
- func (s *RingBufferSink) Close() error
- func (s *RingBufferSink) Flush() error
- func (s *RingBufferSink) Snapshot(processID string, stream uint8) []byte
- func (s *RingBufferSink) SnapshotFiltered(processID string, stream uint8, since time.Time, lines int) []byte
- func (s *RingBufferSink) Write(e LogEntry) error
- type RotatorOptions
- type Sink
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) 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`.
type CollectorOptions ¶
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.
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
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
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.)
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.
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.