parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotString = errors.New("no string in log body")
	ErrNotJson   = errors.New("no json object in log body")
)

Functions

func ExecuteParsers

func ExecuteParsers(parsers []Parser, log *types.Log, message string, name string)

func IsValidParser

func IsValidParser(parserType string) bool

Types

type JsonParser

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

func NewJsonParser

func NewJsonParser(config JsonParserConfig) (*JsonParser, error)

func (*JsonParser) Parse

func (p *JsonParser) Parse(log *types.Log, msg string) error

Attempts to parse the message as JSON and adds the parsed fields to the log body. Not safe for concurrent use.

type JsonParserConfig

type JsonParserConfig struct {
}

type KeyValueParser added in v0.2.0

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

func NewKeyValueParser added in v0.2.0

func NewKeyValueParser(config KeyValueParserConfig) (*KeyValueParser, error)

func (*KeyValueParser) Parse added in v0.2.0

func (p *KeyValueParser) Parse(log *types.Log, msg string) error

Parse parses a space-separated string of key-value pairs and standalone keys and adds them to the log.Body map.

type KeyValueParserConfig added in v0.2.0

type KeyValueParserConfig struct{}

type KlogParser added in v0.2.0

type KlogParser struct{}

func NewKlogParser added in v0.2.0

func NewKlogParser(config KlogParserConfig) (*KlogParser, error)

NewKlogParser creates a parser for the klog format. https://kubernetes.io/docs/concepts/cluster-administration/system-logs

func (*KlogParser) Parse added in v0.2.0

func (p *KlogParser) Parse(log *types.Log, msg string) error

type KlogParserConfig added in v0.2.0

type KlogParserConfig struct{}

type Parser

type Parser interface {
	Parse(*types.Log, string) error
}

Parser is the interface for parsing log messages.

func NewParsers

func NewParsers(parserTypes []string, source string) []Parser

NewParsers creates a list of valid parser instances. Invalid parsers or those that cannot be created will be skipped with warning logs including the source string.

type ParserConfig

type ParserConfig struct {
	Type ParserType
}

ParserConfig is a structure used in configs for creating parsers instances.

type ParserType

type ParserType string
const ParserTypeJson ParserType = "json"
const ParserTypeKeyValue ParserType = "keyvalue"
const ParserTypeKlog ParserType = "klog"
const ParserTypeSpace ParserType = "space"

type SpaceParser added in v0.2.0

type SpaceParser struct{}

func NewSpaceParser added in v0.2.0

func NewSpaceParser(config SpaceParserConfig) (*SpaceParser, error)

func (*SpaceParser) Parse added in v0.2.0

func (p *SpaceParser) Parse(log *types.Log, msg string) error

Parse splits the message by whitespace and adds each field to the log body with a numeric index. For example, "hello world" becomes {"field0": "hello", "field1": "world"} This is useful for parsing generic log lines where fields are separated by one or more spaces. This parser uses strings.Fields, which splits on any whitespace, including tabs and newlines.

type SpaceParserConfig added in v0.2.0

type SpaceParserConfig struct{}

Jump to

Keyboard shortcuts

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