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) {