Skip to content

Commit

Permalink
fix endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ansel1 committed Sep 26, 2019
1 parent e56e7d9 commit 3b13c93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (l *Core) sweetenFields(args []interface{}) []zap.Field {
// passed a bare arg with no key. We'll handle this
// as a special case
fields = append(fields, zap.Any("", args[0]))
return fields
}

// Make sure this element isn't a dangling key.
Expand Down
19 changes: 19 additions & 0 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,22 @@ func TestAddCallerSkip(t *testing.T) {
logSomething(c)
assert.Contains(t, buf.String(), "caller:flume/log_test.go:")
}

func TestSingleArgument(t *testing.T) {
f := NewFactory()
f.SetDefaultLevel(DebugLevel)
f.SetAddCaller(true)

c := f.NewCore("green")

buf := bytes.NewBuffer(nil)
f.SetOut(buf)

c.Info("green", "red")
assert.NotContains(t, buf.String(), _oddNumberErrMsg)

buf.Reset()

c.Info("green", "color", "red", "yellow")
assert.Contains(t, buf.String(), _oddNumberErrMsg)
}

0 comments on commit 3b13c93

Please sign in to comment.