Documentation
¶
Overview ¶
Package parser provides log file reading and parsing functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandGlobs ¶
ExpandGlobs expands a list of file paths and glob patterns into a deduplicated list of matching file paths. Patterns that don't match any files are returned as-is (the caller should handle file-not-found errors).
Types ¶
type FileSource ¶
type FileSource struct {
// contains filtered or unexported fields
}
FileSource implements LogSource for reading from log files.
func NewFileSource ¶
func NewFileSource(files []string, pattern *regexp.Regexp, layout string) *FileSource
NewFileSource creates a LogSource that reads from the given files. The timestamp pattern and layout are used to extract timestamps from each line.
func (*FileSource) Next ¶
func (s *FileSource) Next(ctx context.Context) (*ParsedLine, error)
Next returns the next parsed log line. Skips lines that don't match the timestamp pattern. Returns io.EOF when all files have been exhausted.
type LogLine ¶
type LogLine struct {
// Content is the raw line text.
Content string
// Source is the file path this line came from.
Source string
// LineNum is the 1-based line number in the source file.
LineNum int
}
LogLine is a raw log line before timestamp parsing.
type LogSource ¶
type LogSource interface {
// Next returns the next parsed log line.
// Returns io.EOF when no more lines are available.
// Lines that cannot be parsed (e.g., no timestamp) are skipped.
Next(ctx context.Context) (*ParsedLine, error)
// Close releases any resources held by the source.
Close() error
}
LogSource provides an iterator over parsed log lines. Implementations must be safe for sequential access (not concurrent).
type MergedSource ¶
type MergedSource struct {
// contains filtered or unexported fields
}
MergedSource combines multiple LogSources into a single stream ordered by timestamp (oldest first). This enables cross-service correlation by providing a unified timeline.
func NewMergedSource ¶
func NewMergedSource(sources ...LogSource) *MergedSource
NewMergedSource creates a LogSource that merges multiple sources by timestamp. Lines are returned in chronological order across all sources.
func (*MergedSource) Close ¶
func (m *MergedSource) Close() error
Close releases all source resources.
func (*MergedSource) Next ¶
func (m *MergedSource) Next(ctx context.Context) (*ParsedLine, error)
Next returns the next log line in timestamp order across all sources. Returns io.EOF when all sources are exhausted.
type ParsedLine ¶
type ParsedLine struct {
// Raw is the original line content.
Raw string
// Timestamp is the parsed timestamp from the log line.
Timestamp time.Time
// Source is the file path this line came from.
Source string
// LineNum is the 1-based line number in the source file.
LineNum int
}
ParsedLine represents a single log line with extracted metadata.
type TimestampExtractor ¶
type TimestampExtractor struct {
// contains filtered or unexported fields
}
TimestampExtractor extracts and parses timestamps from log lines.
func NewTimestampExtractor ¶
func NewTimestampExtractor(pattern *regexp.Regexp, layout string) *TimestampExtractor
NewTimestampExtractor creates a new timestamp extractor.