types

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MessageKey = "MESSAGE"

Variables

This section is empty.

Functions

func IsError

func IsError(err error, otherError error) bool

isError checks if err was caused by otherError.

func LoggerWithReaderID

func LoggerWithReaderID(logger log.Logger, readerID ReaderID) log.Logger

LoggerWithReaderID adds the reader_id meta to the logger.

Types

type Action

type Action interface {
	// PerformAction does something with matched messages.
	PerformAction(ctx context.Context, messages []Message) error
}

Action defines an action to perform when a match is found.

type Fields

type Fields map[string]string

Fields contains the message key-value pairs.

type Formatter

type Formatter interface {
	// Format formats the message.
	Format(*bytes.Buffer, Message) error
}

Formatter formats the message.

type FormatterFunc

type FormatterFunc func(*bytes.Buffer, Message) error

FormatterFunc allows functions to implement Formatter.

func (FormatterFunc) Format

func (f FormatterFunc) Format(buf *bytes.Buffer, message Message) error

Format implements Formatter.

type Matcher

type Matcher interface {
	MatchMessage(message Message) bool
}

type Message

type Message struct {
	Timestamp time.Time `json:"ts"`                  // Timestamp of the event.
	Cursor    string    `json:"cursor,omitempty"`    // Cursor position of the message.
	Fields    Fields    `json:"fields,omitempty"`    // Fields contains message fields.
	Source    Source    `json:"source,omitempty"`    // Source the message was read from.
	ReaderID  ReaderID  `json:"reader_id,omitempty"` // ReaderID that read the message.
}

Message is the main log message.

func NewMessage

func NewMessage(
	timestamp time.Time,
	readerID ReaderID,
	text string,
	extra Fields,
) Message

NewMessage is a helper function for creating a Message. The text will be added as the MESSAGE field.

func (*Message) Text

func (m *Message) Text() string

type Persister

type Persister interface {
	// LoadState loads the reader state. When the state doees not exist, it must
	// return no error.
	LoadState(context.Context, ReaderID) (State, error)
	// SaveSave saves the reader state.
	SaveState(context.Context, ReaderID, State) error
}

Persister is a component for loading and reading reader state.

type Processor

type Processor interface {
	// ProcessMessage processes the message read.
	ProcessMessage(context.Context, Message) error
	Tick(context.Context, time.Time) error
}

Processor is a message processor.

type ReadLogsParams

type ReadLogsParams struct {
	State State          // State for resuming reading.
	Ch    chan<- Message // Ch is a channel to write the messages to.
}

ReadLogsParams contains parameters for Reader.ReadLogs.

func (ReadLogsParams) Send

func (w ReadLogsParams) Send(ctx context.Context, message Message) error

ReadLogsParams is a convenience wrapper that tries to send to Ch until the ctx is done.

type Reader

type Reader interface {
	// ReaderID returns the reader's ID.
	ReaderID() ReaderID
	// ReadLogs reads logs until context is done, or an error is encountered.
	// Implementations must not close the ReadLogsParams.Ch as that is done
	// conditionally in Watcher.
	ReadLogs(context.Context, ReadLogsParams) error
}

Reader describes a component that can read logs.

type ReaderID

type ReaderID string

ReaderID is a unique ID of a reader.

type ReaderParams

type ReaderParams struct {
	ReaderID ReaderID
	Logger   log.Logger
}

ReaderParams contains common parameters for all Reader implementations.

type Source

type Source int

Source describes the message source.

const (
	SourceUndefined Source = iota // SourceUndefined is the default.
	SourceStdout                  // SourceStdout means the message was read from stdout.
	SourceStderr                  // SourceStderr means the message was read from stderr.
)

type State

type State struct {
	// Timestamp is the last timestamp read.
	Timestamp time.Time `json:"time"`
	// NumMessages is the number of messages read with the same Timestamp.
	NumMessages int `json:"num_messages"`
	// Cursor is the current cursor, if any.
	Cursor string `json:"cursor,omitempty"`
}

State describes the reader state.

func (State) String

func (s State) String() string

String implements fmt.Stringer.

func (State) WithCursor

func (s State) WithCursor(cursor string) State

WithCursor returns a new State with cursor.

func (State) WithTimestamp

func (s State) WithTimestamp(timestamp time.Time) State

WithTimestamp returns a new State with timestamp set. If the timestamp has advanced, the NumMessages is reset.

Jump to

Keyboard shortcuts

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