renderer

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 12

Documentation

Overview

Package renderer exports the capability to render a LogDog log stream to an io.Writer.

  • Text streams are rendered by emitting the logs and their newlines in order.
  • Binary streams are rendered by emitting the sequential binary data verbatim.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatagramWriter

type DatagramWriter func(io.Writer, []byte) bool

DatagramWriter is a callback function that, given datagram bytes, writes them to the specified io.Writer.

Returns true if the datagram was successfully rendered, false if it could not be.

type Renderer

type Renderer struct {
	// Source is the log Source to use to retrieve the logs to render.
	Source Source

	// Raw, if true, attempts to reproduce the original stream data rather
	// than pretty-rendering it.
	//
	// - For text streams, this means using the original streams' encoding and
	//   newline delimiters. If this is false, UTF8 and "\n" will be used.
	// - For binary and datagram streams, this skips any associated
	//   DatagramWriters and hex translation and dumps data directly to output.
	Raw bool

	// TextPrefix, if not nil, is called prior to rendering a text line. The
	// resulting string is prepended to that text line on render.
	TextPrefix func(le *logpb.LogEntry, line *logpb.Text_Line) string

	// DatagramWriter is a function to call to render a complete datagram stream.
	// If it returns false, or if nil, a hex dump renderer will be used to
	// render the datagram.
	DatagramWriter DatagramWriter
	// contains filtered or unexported fields
}

Renderer is a stateful instance that provides an io.Reader interface to a log stream.

func (*Renderer) Read

func (r *Renderer) Read(b []byte) (int, error)

type Source

type Source interface {
	// NextLogEntry returns the next successive LogEntry record to render, or an
	// error if it could not be retrieved.
	//
	// If there are no more log entries in the stream, NextLogEntry should return
	// io.EOF as an error.
	//
	// It is valid to return a LogEntry and an error (including io.EOF) at the
	// same time. The LogEntry will be processed before the error.
	NextLogEntry() (*logpb.LogEntry, error)
}

Source returns successive LogEntry records for processing.

type StaticSource

type StaticSource []*logpb.LogEntry

StaticSource is a Source that returns successive log entries from a slice of log entries. The slice is mutated during processing.

func (*StaticSource) NextLogEntry

func (s *StaticSource) NextLogEntry() (le *logpb.LogEntry, err error)

NextLogEntry implements Source.

Jump to

Keyboard shortcuts

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