Skip to content

Commit 661a290

Browse files
committed
look for a timestamp only at the beginning of each line
1 parent 1fd0db6 commit 661a290

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clean.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"strings"
66
)
77

8+
const (
9+
lookForTimestampLimit = 30
10+
)
11+
812
var (
913
timestampRegexes = []*regexp.Regexp{
1014
regexp.MustCompile(`(^|\s)\d{2}:\d{2}(:\d{2}[^\s"']*)?`),
@@ -28,6 +32,9 @@ func clean(line string) string {
2832
}
2933

3034
func containsTimestamp(line string) bool {
35+
if len(line) > lookForTimestampLimit {
36+
line = line[:lookForTimestampLimit]
37+
}
3138
for _, re := range timestampRegexes {
3239
if re.MatchString(line) {
3340
return true

multiline_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,13 @@ Caused by: java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1:
166166
writeByLine(m, dateStr+javaStackTraceStr)
167167
msg = <-m.Messages
168168
assert.Equal(t, javaStackTraceStr, msg.Content)
169+
170+
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}}}
171+
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"}
172+
`
173+
writeByLine(m, data)
174+
msg = <-m.Messages
175+
assert.Equal(t,
176+
clean(strings.Split(data, "\n")[0]),
177+
msg.Content)
169178
}

0 commit comments

Comments
 (0)