Documentation ¶
Index ¶
- Variables
- type ContentType
- type EntryFormatter
- type FormatJSON
- type FormatSSE
- type FormatText
- type JournalEntryMatch
- type Option
- func OptionLimit(n uint64) Option
- func OptionMatch(m []JournalEntryMatch) Option
- func OptionMatchOR(m []JournalEntryMatch) Option
- func OptionReadReverse(reverse bool) Option
- func OptionSeekCursor(c string) Option
- func OptionSince(d time.Duration) Option
- func OptionSkipNext(n uint64) Option
- func OptionSkipPrev(n uint64) Option
- type Reader
Constants ¶
This section is empty.
Variables ¶
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") )
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 ¶
Option is a functional option that configures a Reader.
func OptionLimit ¶
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 ¶
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 ¶
OptionSeekCursor is a functional option that seeks a cursor in the journal.
func OptionSince ¶
OptionSince is a functional option that implements journalctl --since analogue.
func OptionSkipNext ¶
OptionSkipNext is a functional option that skips forward N journal entries from the current cursor position.
func OptionSkipPrev ¶
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 ¶
Close is a function to close the journal. Along with Read() function it implements io.ReadCloser
func (*Reader) Follow ¶
Follow is a wrapper function, which can be called multiple times to mimic a journal tailing.
func (*Reader) Read ¶
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 ¶
SeekCursor looks for a specific cursor in the journal and moves to it. Function returns an error if cursor not found.