From 5affde888c2051f0b803758cd1fe620c8e2ce472 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 13 Oct 2022 22:57:31 +0300 Subject: [PATCH] fields fix Signed-off-by: Vasiliy Tolstov --- zerolog.go | 2 +- zerolog_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zerolog.go b/zerolog.go index 02b3c81..3e29a4b 100644 --- a/zerolog.go +++ b/zerolog.go @@ -33,7 +33,7 @@ func (l *zeroLogger) Clone(opts ...logger.Option) logger.Logger { for _, o := range opts { o(&nl.opts.Options) } - + nl.opts.Options.Fields = append(l.opts.Options.Fields, nl.opts.Options.Fields...) _ = nl.Init() return nl } diff --git a/zerolog_test.go b/zerolog_test.go index 6b295c7..cda275c 100644 --- a/zerolog_test.go +++ b/zerolog_test.go @@ -25,9 +25,9 @@ func TestFields(t *testing.T) { t.Fatalf("logger fields not works, buf contains: %s", buf.Bytes()) } buf.Reset() - mnl := l.Fields(map[string]interface{}{"key": "val"}) + mnl := nl.Fields("key1", "val1") mnl.Infof(ctx, "message") - if bytes.Contains(buf.Bytes(), []byte(`"key":"val"`)) { + if !bytes.Contains(buf.Bytes(), []byte(`"key1":"val1"`)) || !bytes.Contains(buf.Bytes(), []byte(`"key":"val"`)) { t.Fatalf("logger fields not works, buf contains: %s", buf.Bytes()) } }