From ffaf129ddbaa5cf87303706a887c5ac9a4890f24 Mon Sep 17 00:00:00 2001 From: charlie <3140647@qq.com> Date: Wed, 11 May 2022 17:24:44 +0800 Subject: [PATCH] fix WithField error --- logx/logrus.go | 8 +++++--- logx/logrus_test.go | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/logx/logrus.go b/logx/logrus.go index a68007e..6bc5f99 100644 --- a/logx/logrus.go +++ b/logx/logrus.go @@ -27,11 +27,13 @@ func (l *logrusWrpper) SetLevel(level Level) { } func (l *logrusWrpper) WithField(key string, value any) Logger { - return l.WithFields(Fields{key: value}) + return l.WithFields(Fields{key: value}).(*logrusWrpper) } func (l *logrusWrpper) WithFields(fields Fields) Logger { - return &logrusWrpper{ - Entry: l.Logger.WithFields(logrus.Fields(fields)), + l = &logrusWrpper{ + Entry: l.Entry.WithFields(logrus.Fields(fields)), } + + return l } diff --git a/logx/logrus_test.go b/logx/logrus_test.go index 4a607ad..bd4b4ab 100644 --- a/logx/logrus_test.go +++ b/logx/logrus_test.go @@ -26,6 +26,9 @@ func TestLogrus(t *testing.T) { l.WithField("abc", "bcd").Info("aaaa") l.WithField("bbb", "bbb").Info("bbbb") l.WithField("ccc", "ccc").Info("cccc") + + l = l.WithField("o", "o") + l.WithField("z", "z").Info("abcd") } func TestLevel(t *testing.T) {