parse

package
v0.0.0-...-80aa0b4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayLines

func DisplayLines(extraction []Extraction)

func DisplayTestLines

func DisplayTestLines(extraction []Extraction)

func Export

func Export(w io.Writer, format string, extractions []Extraction) error

Export writes the extracted records to w in the given format. Supported formats are "json" (a pretty-printed array), "ndjson" (one JSON object per line) and "csv" (a table with one column per token).

func FormatFromPath

func FormatFromPath(path string) string

FormatFromPath infers an export format from a file extension, returning an empty string when the extension is unrecognised.

func FprintExtraction

func FprintExtraction(w io.Writer, e Extraction)

FprintExtraction writes a single extraction in the human-readable form used by the print output. It is used when streaming records one at a time.

func ParseStream

func ParseStream(r io.Reader, config *Config, follow bool, emit func(Extraction) error) error

ParseStream reads lines from r one at a time and calls emit with the extraction for each non-blank line as soon as the line is available. Only single-line patterns are considered, since streaming cannot look ahead for multi-line patterns.

When follow is true, reaching the end of the input means "wait for more data" rather than "done", so a growing file can be tailed; the call then returns only on error or an emit failure. When follow is false it returns at EOF, which also lets it stream naturally from a pipe (each line is emitted as soon as it is written, and the pipe closing ends the stream).

Types

type Config

type Config struct {
	Tokens       []string              `json:"tokens"`
	Patterns     []string              `json:"patterns"`
	Dependencies map[string][]string   `json:"dependencies,omitempty"`
	Conversions  map[string]Conversion `json:"conversions,omitempty"`
}

func LoadConfig

func LoadConfig(path string) (Config, error)

type Conversion

type Conversion struct {
	Token      string  `json:"token"`
	Multiplier float64 `json:"multiplier"`
}

type Extraction

type Extraction struct {
	Params     map[string]Param `json:"params"`
	Pattern    string           `json:"pattern"`
	LineNumber int              `json:"lineNumber"`
	Line       string           `json:"line"`
}

func Parse

func Parse(logtext string, config *Config) ([]Extraction, error)

Parse separates the log text into lines and attempts to extract tokens parameters from each line using the most appropriate pattern in the given config.

func ParseFile

func ParseFile(path string, config *Config) ([]Extraction, error)

ParseFile streams the log text from the given file path and attempts to extract token parameters from each line using the most appropriate pattern in the given config.

func ParseFileTest

func ParseFileTest(path string, config *Config) ([]Extraction, error)

ParseTest runs ParseFile and displays a random sample of extracted parameters along with the origin lines from the log file.

func ParseFiles

func ParseFiles(paths []string, config *Config) ([]Extraction, error)

ParseFile reads the log text from each of the given file paths, separates the text into lines and attempts to extract tokens parameters from each line using the most appropriate pattern in the given config.

func ParseFilesTest

func ParseFilesTest(paths []string, config *Config) ([]Extraction, error)

ParseTest runs ParseFiles and displays a random sample of extracted parameters along with the origin lines from the log files.

func ParseLines

func ParseLines(lines []string, config *Config) ([]Extraction, error)

ParseLines attempts to extract token parameters from each line using the most appropriate pattern in the given config. When the config contains no multi-line patterns the lines are parsed concurrently; otherwise a sequential pass is used so lines consumed by a multi-line match are skipped correctly. Both paths produce identical, in-order results.

func ParseReader

func ParseReader(r io.Reader, config *Config) ([]Extraction, error)

ParseReader streams log lines from r and extracts token parameters from each line using the most appropriate pattern in the given config. Reading from a stream avoids holding a second full-size copy of the log in memory, so it scales to large files and also supports stdin.

func ParseTest

func ParseTest(logtext string, config *Config) []Extraction

ParseTest runs Parse and displays a random sample of extracted parameters along with the origin lines from the log text.

type ExtractionDebug

type ExtractionDebug struct {
	Line       string         `json:"line"`
	LineNumber int            `json:"lineNumber"`
	Pattern    string         `json:"pattern"`
	Params     map[string]any `json:"params"`
}

type Param

type Param struct {
	Value any    `json:"value"`
	Type  string `json:"type"`
}

type PatternRank

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

Jump to

Keyboard shortcuts

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