xlog

package
v0.0.0-...-5eee607 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package xlog is an xlogfile parsing and manipulation library.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoFile = errors.New("xlog file not found")

ErrNoFile means an attempt was made to read a missing xlog

Functions

func FindSeparator

func FindSeparator(s string) int

FindSeparator finds the first non-escaped occurrence of the xlog separator ':' in the string and returns the byte offset of that occurrence, or -1 if the separator is not present in the string.

func IsKeyHidden

func IsKeyHidden(key string) bool

IsKeyHidden checks if key is a *hidden* xlog fieldname

func IsPotentialXlogLine

func IsPotentialXlogLine(line string) bool

IsPotentialXlogLine returns true if line looks like it might be a valid Xlog line. This is a convenient shortcut to discard trivial invalid lines such as blank lines and lines starting with colons.

It is the caller's responsibility to strip any extraneous leading and trailing space, including trailing newlines.

func QuoteValue

func QuoteValue(value string) string

QuoteValue quotes an Xlog value field by escaping embedded ":" as "::".

func UnquoteValue

func UnquoteValue(value string) string

UnquoteValue unquotes an Xlog value, replacing "::" with ":".

Types

type ParseError

type ParseError struct {
	Line         string
	Cause        string
	ErrByteIndex int
}

A ParseError is an error in parsing an xlog line.

func (*ParseError) ErrRuneIndex

func (e *ParseError) ErrRuneIndex() int

ErrRuneIndex gets the rune index of the parse error in the xlog Line.

func (*ParseError) Error

func (e *ParseError) Error() string

type Reader

type Reader struct {
	// SourceKey is a unique identifier for the server this logfile is from
	SourceKey string

	Path     string
	Filename string
	File     *os.File
	Offset   int64
	Reader   *bufio.Reader
}

A Reader reads xlog entries from a logfile.

func NewReader

func NewReader(sourceKey, filepath, dbFilename string) *Reader

NewReader creates a new Reader for the given absolute path, and dbFilename. The dbFilename will be saved as the filename in the database.

func (*Reader) BackToLastCompleteLine

func (x *Reader) BackToLastCompleteLine() error

BackToLastCompleteLine rewinds the XlogReader to the end of the last complete line read, or the last place explicitly Seek()ed to; does nothing if nothing read yet.

func (*Reader) Close

func (x *Reader) Close() error

Close closes the Reader's file handle.

func (*Reader) Next

func (x *Reader) Next() (Xlog, error)

Next reads the next xlog entry from the logfile, skipping blank lines. When EOF is reached, returns nil with no error.

func (*Reader) ReadAll

func (x *Reader) ReadAll() ([]Xlog, error)

ReadAll reads all available Xlog lines from the source; use only for testing.

func (*Reader) ReadCompleteLine

func (x *Reader) ReadCompleteLine() (string, error)

ReadCompleteLine reads a complete line from the Xlog reader, returning an empty string if it can't read a full \n-terminated line. The line returned is always empty or \n-terminated.

func (*Reader) SeekNext

func (x *Reader) SeekNext(offset int64) error

SeekNext seeks to the given offset, then reads and discards one complete line. This is convenient if you have the offset of the last processed line and want to resume reading on the next line.

func (*Reader) SeekOffset

func (x *Reader) SeekOffset(offset int64) error

SeekOffset seeks to the given offset from the start of the file.

func (*Reader) String

func (x *Reader) String() string

type Xlog

type Xlog map[string]string

An Xlog is a mapping of xlog keys to values, where both keys and values are strings.

func Parse

func Parse(line, sourceKey string) (Xlog, error)

Parse parses the given xlog line into an Xlog object.

func (Xlog) Clone

func (x Xlog) Clone() Xlog

Clone returns a copy of x.

func (Xlog) Contains

func (x Xlog) Contains(key string) bool

Contains checks if x contains key.

func (Xlog) Get

func (x Xlog) Get(name string) string

Get gets the xlog value for the field name.

func (Xlog) String

func (x Xlog) String() string

Jump to

Keyboard shortcuts

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