reader

package
v0.0.0-...-1ad4746 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2018 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCursorFormat is the error thrown by OptionSeekCursor if cursor string is invalid.
	ErrCursorFormat = errors.New("Incorrect cursor string")

	// ErrInvalidDuration is the error thrown by OptionSince if negative or zero duration used.
	ErrInvalidDuration = errors.New("Invalid duration parameter")
)
View Source
var ErrUninitializedReader = errors.New("NewReader() must be called before using journal reader")

ErrUninitializedReader is the error returned by Reader is contentFormatter wasn't initialized. An instance of Reader must always be obtained by calling `NewReader` constructor function.

Functions

This section is empty.

Types

type ContentType

type ContentType string

ContentType is used in response header.

var (
	// ContentTypePlainText is a ContentType header for plain text logs.
	ContentTypePlainText ContentType = "text/plain"

	// ContentTypeApplicationJSON is a ContentType header for json logs.
	ContentTypeApplicationJSON ContentType = "application/json"

	// ContentTypeEventStream is a ContentType header for event-stream logs.
	ContentTypeEventStream ContentType = "text/event-stream"
)

func (ContentType) String

func (c ContentType) String() string

String returns a string representation of type "ContentType"

type EntryFormatter

type EntryFormatter interface {
	// GetContentType returns a content type for the entry formatter.
	GetContentType() ContentType

	// FormatEntry accepts `sdjournal.JournalEntry` and returns an array of bytes.
	FormatEntry(*sdjournal.JournalEntry) ([]byte, error)
}

EntryFormatter is an interface used by journal to write in a specific format.

func NewEntryFormatter

func NewEntryFormatter(s string, useCursorID bool) EntryFormatter

NewEntryFormatter returns a new implementation of EntryFormatter corresponding to a given content type.

type FormatJSON

type FormatJSON struct{}

FormatJSON implements EntryFormatter for json logs.

func (FormatJSON) FormatEntry

func (j FormatJSON) FormatEntry(entry *sdjournal.JournalEntry) ([]byte, error)

FormatEntry formats sdjournal.JournalEntry to a json log entry.

func (FormatJSON) GetContentType

func (j FormatJSON) GetContentType() ContentType

GetContentType returns "application/json"

type FormatSSE

type FormatSSE struct {
	UseCursorID bool
}

FormatSSE implements EntryFormatter for server sent event logs. Must be in the following format: data: {...}\n\n

func (FormatSSE) FormatEntry

func (j FormatSSE) FormatEntry(entry *sdjournal.JournalEntry) ([]byte, error)

FormatEntry formats sdjournal.JournalEntry to a server sent event log entry.

func (FormatSSE) GetContentType

func (j FormatSSE) GetContentType() ContentType

GetContentType returns "text/event-stream"

type FormatText

type FormatText struct{}

FormatText implements EntryFormatter for text logs.

func (FormatText) FormatEntry

func (j FormatText) FormatEntry(entry *sdjournal.JournalEntry) ([]byte, error)

FormatEntry formats sdjournal.JournalEntry to a text log line.

func (FormatText) GetContentType

func (j FormatText) GetContentType() ContentType

GetContentType returns "text/plain"

type JournalEntryMatch

type JournalEntryMatch struct {
	Field, Value string
}

JournalEntryMatch is a convenience wrapper to describe filters supplied to AddMatch.

func (*JournalEntryMatch) String

func (m *JournalEntryMatch) String() string

String returns a string representation of a Match suitable for use with AddMatch.

type Option

type Option func(*Reader) error

Option is a functional option that configures a Reader.

func OptionLimit

func OptionLimit(n uint64) Option

OptionLimit is a functional option sets a limit of entries to read from a journal.

func OptionMatch

func OptionMatch(m []JournalEntryMatch) Option

OptionMatch is a functional option that filters entries based on []JournalEntryMatch.

func OptionMatchOR

func OptionMatchOR(m []JournalEntryMatch) Option

OptionMatchOR is a functional option that filters entries and applies logical OR to user arguments []JournalEntryMatch.

func OptionReadReverse

func OptionReadReverse(reverse bool) Option

OptionReadReverse is a functional option sets a reverse direction to read the journal. By default we always read the journal up to down. If we use this option, we'll be reading the journal in reverse.

func OptionSeekCursor

func OptionSeekCursor(c string) Option

OptionSeekCursor is a functional option that seeks a cursor in the journal.

func OptionSince

func OptionSince(d time.Duration) Option

OptionSince is a functional option that implements journalctl --since analogue.

func OptionSkipNext

func OptionSkipNext(n uint64) Option

OptionSkipNext is a functional option that skips forward N journal entries from the current cursor position.

func OptionSkipPrev

func OptionSkipPrev(n uint64) Option

OptionSkipPrev is a functional option that skips backward N journal entries from the current cursor position.

type Reader

type Reader struct {
	Journal                  *sdjournal.Journal
	Cursor                   string
	Limit                    uint64
	UseLimit                 bool
	SkippedNext, SkippedPrev uint64
	ReadReverse              bool
	// contains filtered or unexported fields
}

Reader is the main Journal Reader structure. It implements Reader interface.

func NewReader

func NewReader(contentFormatter EntryFormatter, options ...Option) (r *Reader, err error)

NewReader returns a new instance of journal reader.

func (*Reader) Close

func (r *Reader) Close() error

Close is a function to close the journal. Along with Read() function it implements io.ReadCloser

func (*Reader) Follow

func (r *Reader) Follow(wait time.Duration, writer io.Writer) error

Follow is a wrapper function, which can be called multiple times to mimic a journal tailing.

func (*Reader) Read

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

Read is implementation of Reader interface. Most of the code was taken from https://github.com/coreos/go-systemd/blob/master/sdjournal/read.go

func (*Reader) SeekCursor

func (r *Reader) SeekCursor(c string) error

SeekCursor looks for a specific cursor in the journal and moves to it. Function returns an error if cursor not found.

func (*Reader) SkipNext

func (r *Reader) SkipNext(n uint64) error

SkipNext skips a journal by n entries forward.

func (*Reader) SkipPrev

func (r *Reader) SkipPrev(n uint64) error

SkipPrev skips a journal by n entries backwards.

Jump to

Keyboard shortcuts

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