Skip to content

Commit

Permalink
expand datetime search to the first 100 characters of a log line
Browse files Browse the repository at this point in the history
  • Loading branch information
def committed Oct 4, 2023
1 parent 06ae2b9 commit 46cfc42
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 134 deletions.
11 changes: 1 addition & 10 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package logparser

import (
"regexp"
"strings"
)

const (
lookForTimestampLimit = 30
lookForTimestampLimit = 100
)

var (
Expand All @@ -21,16 +20,8 @@ var (
regexp.MustCompile(`\d{2}/\d{2}/\d{4}`),
regexp.MustCompile(`\d{2}\.\d{2}\.\d{4}`),
}
extraSpaces = regexp.MustCompile(`\s+`)
)

func clean(line string) string {
for _, r := range timestampRegexes {
line = r.ReplaceAllString(line, "")
}
return strings.TrimSpace(extraSpaces.ReplaceAllString(line, " "))
}

func containsTimestamp(line string) bool {
if len(line) > lookForTimestampLimit {
line = line[:lookForTimestampLimit]
Expand Down
4 changes: 3 additions & 1 deletion multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logparser

import (
"context"
"fmt"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -33,7 +34,7 @@ type MultilineCollector struct {
func NewMultilineCollector(ctx context.Context, timeout time.Duration) *MultilineCollector {
m := &MultilineCollector{
timeout: timeout,
Messages: make(chan Message, 1),
Messages: make(chan Message, 100),
}
go m.dispatch(ctx)
return m
Expand Down Expand Up @@ -88,6 +89,7 @@ func (m *MultilineCollector) add(entry LogEntry) {
m.level = entry.Level
}
m.isFirstLineContainsTimestamp = containsTimestamp(entry.Content)
fmt.Println(m.isFirstLineContainsTimestamp, entry.Content)
}
m.appendLine(entry.Content)
m.lastReceiveTime = time.Now()
Expand Down
Loading

0 comments on commit 46cfc42

Please sign in to comment.