Skip to content

Commit

Permalink
Capture newlines in log stdlib (#1041)
Browse files Browse the repository at this point in the history
Capture newlines in the stdlib adapter messages. Avoids cutting off
multi-line log messages.

See: prometheus/node_exporter#1886

Signed-off-by: Ben Kochie <superq@gmail.com>
  • Loading branch information
SuperQ authored Nov 30, 2020
1 parent a055839 commit 0ca2279
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions log/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const (
logRegexpDate = `(?P<date>[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?`
logRegexpTime = `(?P<time>[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?)?[ ]?`
logRegexpFile = `(?P<file>.+?:[0-9]+)?`
logRegexpMsg = `(: )?(?P<msg>.*)`
logRegexpMsg = `(: )?(?P<msg>(?s:.*))`
)

var (
Expand All @@ -145,7 +145,7 @@ func subexps(line []byte) map[string]string {
}
result := map[string]string{}
for i, name := range logRegexp.SubexpNames() {
result[name] = string(m[i])
result[name] = strings.TrimRight(string(m[i]), "\n")
}
return result
}
6 changes: 6 additions & 0 deletions log/stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ func TestStdlibAdapterSubexps(t *testing.T) {
"file": "",
"msg": "hello world",
},
"hello\nworld": {
"date": "",
"time": "",
"file": "",
"msg": "hello\nworld",
},
"2009/01/23: hello world": {
"date": "2009/01/23",
"time": "",
Expand Down

0 comments on commit 0ca2279

Please sign in to comment.