Skip to content

Commit

Permalink
handle another possible stackdriver format
Browse files Browse the repository at this point in the history
  • Loading branch information
jrockway committed May 1, 2021
1 parent f605840 commit 21e541c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions integration-tests/loggers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ func TestLoggers(t *testing.T) {
l.WithError(exampleError).Info("line 3")
},
},
{
name: "logrus/json-stackdriver",
ins: &parse.InputSchema{
LevelKey: "severity",
MessageKey: "message",
TimeKey: "time",
LevelFormat: parse.DefaultLevelParser,
TimeFormat: parse.DefaultTimeParser,
Strict: true,
},
f: func(buf *bytes.Buffer) {
l := &logrus.Logger{
Out: buf,
Formatter: &logrus.JSONFormatter{
FieldMap: logrus.FieldMap{
logrus.FieldKeyTime: "time",
logrus.FieldKeyLevel: "severity",
logrus.FieldKeyMsg: "message",
},
TimestampFormat: time.RFC3339Nano,
},
Level: logrus.DebugLevel,
}
l.Info("line 1")
l.WithField("string", "value").WithField("int", 42).WithField("object", exampleObject).Info("line 2")
l.WithError(exampleError).Info("line 3")
},
},
{
name: "lager/pretty",
skip: "we can't handle the extra 'test.' appended to each message",
Expand Down
9 changes: 9 additions & 0 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ func (s *InputSchema) guessSchema(l *line) {
s.MessageKey = "message"
return
}
if has("time") && has("severity") && has("message") {
// another stackdriver format
s.TimeKey = "time"
s.TimeFormat = DefaultTimeParser
s.LevelKey = "severity"
s.LevelFormat = DefaultLevelParser
s.MessageKey = "message"
return
}
if has("time") && has("level") && has("v") && has("msg") {
// bunyan
if v, ok := l.fields["v"].(float64); ok && v == 0 {
Expand Down

0 comments on commit 21e541c

Please sign in to comment.