From 3b13c93b3c352a63c45fd407fc9d0d2956fb1c3b Mon Sep 17 00:00:00 2001 From: Russ Egan Date: Thu, 26 Sep 2019 16:49:49 -0500 Subject: [PATCH] fix endless loop --- core.go | 1 + log_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core.go b/core.go index 241e082..df2a7e2 100644 --- a/core.go +++ b/core.go @@ -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. diff --git a/log_test.go b/log_test.go index 317aac6..e62f8e0 100644 --- a/log_test.go +++ b/log_test.go @@ -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) +}