From 37ae3ae741cb3299f2bc98a5ff43425f584c688e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 20 Jan 2022 01:02:58 +0300 Subject: [PATCH] logger: add logger Fields test Signed-off-by: Vasiliy Tolstov --- zerolog.go | 2 +- zerolog_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/zerolog.go b/zerolog.go index 40e72df..c164b09 100644 --- a/zerolog.go +++ b/zerolog.go @@ -149,7 +149,7 @@ func (l *zeroLogger) Fields(fields ...interface{}) logger.Logger { } func (l *zeroLogger) V(level logger.Level) bool { - return l.zLog.GetLevel() >= loggerToZerologLevel(level) + return l.zLog.GetLevel() <= loggerToZerologLevel(level) } func (l *zeroLogger) Info(ctx context.Context, args ...interface{}) { diff --git a/zerolog_test.go b/zerolog_test.go index 346aad4..b897709 100644 --- a/zerolog_test.go +++ b/zerolog_test.go @@ -12,6 +12,19 @@ import ( "go.unistack.org/micro/v3/logger" ) +func TestFields(t *testing.T) { + ctx := context.TODO() + buf := bytes.NewBuffer(nil) + l := NewLogger(logger.WithLevel(logger.TraceLevel), logger.WithOutput(buf)) + if err := l.Init(); err != nil { + t.Fatal(err) + } + l.Fields("key", "val").Infof(ctx, "message") + if !bytes.Contains(buf.Bytes(), []byte(`"key":"val"`)) { + t.Fatalf("logger fields not works, buf contains: %s", buf.Bytes()) + } +} + func TestOutput(t *testing.T) { buf := bytes.NewBuffer(nil) l := NewLogger(logger.WithOutput(buf))