logreader

package
v3.0.0-rc21 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDrainInterval = 500 * time.Millisecond

DefaultDrainInterval is the default interval for periodic draining in follow mode

View Source
const DefaultMaxEntries = 10000

DefaultMaxEntries is the default maximum number of log entries to keep in memory

Variables

This section is empty.

Functions

func CollectAndSort

func CollectAndSort(streams []NodeStream, output io.Writer, renderer RenderFunc, follow bool, opts ...Option)

CollectAndSort collects log entries from multiple nodes, sorts them by timestamp, and renders them using the provided renderer function.

This function manages the complete lifecycle:

  1. For non-follow mode: collects all backlog, sorts it, renders it, then exits
  2. For follow mode: collects initial backlog, sorts and renders it, then continues with periodic draining every DrainInterval

Parameters: - streams: slice of NodeStream, each containing a node name and its log reader - output: the io.Writer to write sorted log entries to (can be os.Stderr, a text view, etc.) - renderer: function to render each event (receives event, node name, and output writer) - follow: whether to continue reading new logs after initial backlog - opts: optional configuration options (max entries, drain interval)

Entries are automatically dropped when MaxEntries is reached.

func CollectAndSortWithFormat

func CollectAndSortWithFormat(streams []NodeStream, output io.Writer, format string, follow bool, opts ...Option)

CollectAndSortWithFormat is a convenience function that uses the default renderer with the specified format string.

Parameters: - streams: slice of NodeStream, each containing a node name and its log reader - output: the io.Writer to write sorted log entries to (can be os.Stderr, a text view, etc.) - format: the output format (e.g., "", "json") - follow: whether to continue reading new logs after initial backlog - opts: optional configuration options (max entries, drain interval)

Types

type Config

type Config struct {
	// MaxEntries is the maximum number of log entries to keep in memory
	MaxEntries int

	// DrainInterval is the interval for periodic draining in follow mode
	DrainInterval time.Duration
}

Config holds configuration for the log reader

type LogReader

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

LogReader manages multi-node log reading with in-memory sorting

func New

func New(opts ...Option) *LogReader

New creates a new LogReader with the given options

func (*LogReader) Start

func (lr *LogReader) Start(streams []NodeStream, output io.Writer, renderer RenderFunc, follow bool)

Start begins reading from all provided node streams It first collects the backlog, sorts it, and outputs it If follow is enabled, it continues with periodic draining

func (*LogReader) Stop

func (lr *LogReader) Stop()

Stop stops all readers

type NodeStream

type NodeStream struct {
	Node   string
	Reader event.ReadCloser
	Index  int // Position index for prefix selection (0-based)
}

NodeStream represents a single node's log stream

type Option

type Option func(*Config)

Option is a function that modifies Config

func WithDrainInterval

func WithDrainInterval(d time.Duration) Option

WithDrainInterval sets the drain interval for follow mode

func WithHeapSize

func WithHeapSize(size int) Option

WithHeapSize is deprecated, use WithMaxEntries instead

func WithMaxEntries

func WithMaxEntries(size int) Option

WithMaxEntries sets the maximum number of entries to keep in memory

type RenderFunc

type RenderFunc func(streamlog.Event, string, int, io.Writer) error

RenderFunc is a function that renders a log event to an output writer It receives the event, node name, stream index, and output writer This allows callers to customize how events are rendered

func DefaultRenderFunc

func DefaultRenderFunc(format string, numStreams int) RenderFunc

DefaultRenderFunc returns a default renderer that uses streamlog.Event.Render numStreams is the total number of streams for calculating padding width

Jump to

Keyboard shortcuts

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