Skip to content

Commit

Permalink
test: source package after major changes (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
hedhyw authored Sep 22, 2024
1 parent cdf6dc1 commit 62d6cce
Show file tree
Hide file tree
Showing 7 changed files with 625 additions and 124 deletions.
12 changes: 7 additions & 5 deletions internal/pkg/source/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ type LazyLogEntry struct {
length int
}

// Length of the entry.
func (e LazyLogEntry) Length() int {
return e.length
}

// Line re-reads the line.
func (e LazyLogEntry) Line(file *os.File) (json.RawMessage, error) {
data := make([]byte, e.length)

_, err := file.ReadAt(data, e.offset)
if err != nil {
return nil, err
Expand All @@ -45,7 +48,7 @@ func (e LazyLogEntry) LogEntry(file *os.File, cfg *config.Config) LogEntry {
}
}

return ParseLogEntry(line, cfg)
return parseLogEntry(line, cfg)
}

// LogEntry is a single partly-parse record of the log.
Expand Down Expand Up @@ -90,6 +93,7 @@ func (entries LazyLogEntries) Filter(term string) (LazyLogEntries, error) {
if err != nil {
return LazyLogEntries{}, err
}

if bytes.Contains(bytes.ToLower(line), termLower) {
filtered = append(filtered, f)
}
Expand Down Expand Up @@ -151,8 +155,6 @@ func formatField(
return string(ParseLevel(formatMessage(value), cfg.CustomLevelMapping))
case config.FieldKindTime:
return formatMessage(value)
case config.FieldKindNumericTime:
return formatMessage(value)
case config.FieldKindSecondTime:
return formatMessage(formatTimeString(value, "s"))
case config.FieldKindMilliTime:
Expand All @@ -166,8 +168,8 @@ func formatField(
}
}

// ParseLogEntry parses a single log entry from the json line.
func ParseLogEntry(
// parseLogEntry parses a single log entry from the json line.
func parseLogEntry(
line json.RawMessage,
cfg *config.Config,
) LogEntry {
Expand Down
Loading

0 comments on commit 62d6cce

Please sign in to comment.