logs

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: GPL-3.0 Imports: 16 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 added in v0.22.0

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

type JSONParser added in v0.22.0

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

func NewJSONParser added in v0.22.0

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

func (*JSONParser) Info added in v0.22.0

func (p *JSONParser) Info() string

func (*JSONParser) Parse added in v0.22.0

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

func (*JSONParser) ReadLine added in v0.22.0

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