Documentation
¶
Index ¶
Constants ¶
const DefaultDrainInterval = 500 * time.Millisecond
DefaultDrainInterval is the default interval for periodic draining in follow mode
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:
- For non-follow mode: collects all backlog, sorts it, renders it, then exits
- 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 (*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
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 ¶
WithDrainInterval sets the drain interval for follow mode
func WithHeapSize ¶
WithHeapSize is deprecated, use WithMaxEntries instead
func WithMaxEntries ¶
WithMaxEntries sets the maximum number of entries to keep in memory
type RenderFunc ¶
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