Skip to content

Commit

Permalink
look for a timestamp only at the beginning of each line
Browse files Browse the repository at this point in the history
  • Loading branch information
def committed Mar 25, 2022
1 parent 1fd0db6 commit 661a290
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"strings"
)

const (
lookForTimestampLimit = 30
)

var (
timestampRegexes = []*regexp.Regexp{
regexp.MustCompile(`(^|\s)\d{2}:\d{2}(:\d{2}[^\s"']*)?`),
Expand All @@ -28,6 +32,9 @@ func clean(line string) string {
}

func containsTimestamp(line string) bool {
if len(line) > lookForTimestampLimit {
line = line[:lookForTimestampLimit]
}
for _, re := range timestampRegexes {
if re.MatchString(line) {
return true
Expand Down
9 changes: 9 additions & 0 deletions multiline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,13 @@ Caused by: java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1:
writeByLine(m, dateStr+javaStackTraceStr)
msg = <-m.Messages
assert.Equal(t, javaStackTraceStr, msg.Content)

data := `Order response: {"statusCode":406,"body":{"timestamp":1648205755430,"status":406,"error":"Not Acceptable","exception":"works.weave.socks.orders.controllers.OrdersController$PaymentDeclinedException","message":"Payment declined: amount exceeds 100.00","path":"/orders"},"headers":{"x-application-context":"orders:80","content-type":"application/json;charset=UTF-8","transfer-encoding":"chunked","date":"Fri, 25 Mar 2022 10:55:55 GMT","connection":"close"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"orders","port":80,"hostname":"orders","hash":null,"search":null,"query":null,"pathname":"/orders","path":"/orders","href":"http://orders/orders"},"method":"POST","headers":{"accept":"application/json","content-type":"application/json","content-length":232}}}
Order response: {"timestamp":1648205755430,"status":406,"error":"Not Acceptable","exception":"works.weave.socks.orders.controllers.OrdersController$PaymentDeclinedException","message":"Payment declined: amount exceeds 100.00","path":"/orders"}
`
writeByLine(m, data)
msg = <-m.Messages
assert.Equal(t,
clean(strings.Split(data, "\n")[0]),
msg.Content)
}

0 comments on commit 661a290

Please sign in to comment.