logs

package
v0.0.0-...-6ade924 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeCSV    = "csv"
	TypeLTSV   = "ltsv"
	TypeRegExp = "regexp"
	TypeJSON   = "json"
)
View Source
const DefaultMaxLineWidth = 4 * 1024 // assume disk block size is 4K

Variables

View Source
var (
	ErrNoMatchedFile = errors.New("no matched files")
)
View Source
var ErrTooLongLine = errors.New("too long line")

Functions

func IsParseError

func IsParseError(err error) bool

func ReadLastLine

func ReadLastLine(filename string, maxLineWidth int64) ([]byte, error)

ReadLastLine returns the last line of the file and any read error encountered. It expects last line width <= maxLineWidth. If maxLineWidth <= 0, it defaults to DefaultMaxLineWidth.

Types

type CSVConfig

type CSVConfig struct {
	FieldsPerRecord  int                              `yaml:"fields_per_record"`
	Delimiter        string                           `yaml:"delimiter"`
	TrimLeadingSpace bool                             `yaml:"trim_leading_space"`
	Format           string                           `yaml:"format"`
	CheckField       func(string) (string, int, bool) `yaml:"-"`
}

type CSVParser

type CSVParser struct {
	Config CSVConfig
	// contains filtered or unexported fields
}

func NewCSVParser

func NewCSVParser(config CSVConfig, in io.Reader) (*CSVParser, error)

func (CSVParser) Info

func (p CSVParser) Info() string

func (*CSVParser) Parse

func (p *CSVParser) Parse(row []byte, line LogLine) error

func (*CSVParser) ReadLine

func (p *CSVParser) ReadLine(line LogLine) error

type JSONConfig

type JSONConfig struct {
	Mapping map[string]string `yaml:"mapping"`
}

type JSONParser

type JSONParser struct {
	// contains filtered or unexported fields
}

func NewJSONParser

func NewJSONParser(config JSONConfig, in io.Reader) (*JSONParser, error)

func (*JSONParser) Info

func (p *JSONParser) Info() string

func (*JSONParser) Parse

func (p *JSONParser) Parse(row []byte, line LogLine) error

func (*JSONParser) ReadLine

func (p *JSONParser) ReadLine(line LogLine) error

type LTSVConfig

type LTSVConfig struct {
	FieldDelimiter string            `yaml:"field_delimiter"`
	ValueDelimiter string            `yaml:"value_delimiter"`
	Mapping        map[string]string `yaml:"mapping"`
}

type LTSVParser

type LTSVParser struct {
	// contains filtered or unexported fields
}

func NewLTSVParser

func NewLTSVParser(config LTSVConfig, in io.Reader) (*LTSVParser, error)

func (LTSVParser) Info

func (p LTSVParser) Info() string

func (*LTSVParser) Parse

func (p *LTSVParser) Parse(row []byte, line LogLine) error

func (*LTSVParser) ReadLine

func (p *LTSVParser) ReadLine(line LogLine) error

type LogLine

type LogLine interface {
	Assign(name string, value string) error
}

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

func (ParseError) Error

func (e ParseError) Error() string

func (ParseError) Unwrap

func (e ParseError) Unwrap() error

type Parser

type Parser interface {
	ReadLine(LogLine) error
	Parse(row []byte, line LogLine) error
	Info() string
}

func NewParser

func NewParser(config ParserConfig, in io.Reader) (Parser, error)

type ParserConfig

type ParserConfig struct {
	LogType string       `yaml:"log_type"`
	CSV     CSVConfig    `yaml:"csv_config"`
	LTSV    LTSVConfig   `yaml:"ltsv_config"`
	RegExp  RegExpConfig `yaml:"regexp_config"`
	JSON    JSONConfig   `yaml:"json_config"`
}

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a log rotate aware Reader TODO: better reopen algorithm TODO: handle truncate

func Open

func Open(path string, excludePath string, log *logger.Logger) (*Reader, error)

Open a file and seek to end of the file. path: the shell file name pattern excludePath: the shell file name pattern

func (*Reader) Close

func (r *Reader) Close() (err error)

func (*Reader) CurrentFilename

func (r *Reader) CurrentFilename() string

CurrentFilename get current opened file name

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

type RegExpConfig

type RegExpConfig struct {
	Pattern string `yaml:"pattern"`
}

type RegExpParser

type RegExpParser struct {
	// contains filtered or unexported fields
}

func NewRegExpParser

func NewRegExpParser(config RegExpConfig, in io.Reader) (*RegExpParser, error)

func (RegExpParser) Info

func (p RegExpParser) Info() string

func (*RegExpParser) Parse

func (p *RegExpParser) Parse(row []byte, line LogLine) error

func (*RegExpParser) ReadLine

func (p *RegExpParser) ReadLine(line LogLine) error

Jump to

Keyboard shortcuts

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