Skip to content

Commit

Permalink
fix: concurrency issue (#56)
Browse files Browse the repository at this point in the history
* fix: concurrency issue

* test: add test
  • Loading branch information
davidebianchi authored Sep 7, 2023
1 parent eee5ca0 commit 14a97c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions loggers/logrus/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ func (l Logger) Trace(msg string) {
}

func (l *Logger) WithFields(fields map[string]any) core.Logger[*logrus.Entry] {
entry := l.logger.WithFields(logrus.Fields(fields))
l.logger = entry
return l
return &Logger{logger: l.logger.WithFields(logrus.Fields(fields))}
}

func (l Logger) OriginalLogger() *logrus.Entry {
Expand Down
10 changes: 8 additions & 2 deletions loggers/logrus/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ func TestLogger(t *testing.T) {
logger.WithFields(expectedFields).Info("my msg")
logger.WithFields(expectedFields).Trace("some other")
logger.WithFields(expectedFields).Info("yeah")
logger.Info("ok")

require.Len(t, hook.AllEntries(), 3)
require.Len(t, hook.AllEntries(), 4)
assertLog(t, hook.AllEntries()[0], expectedLog{
Level: "info",
Message: "my msg",
Expand All @@ -130,11 +131,16 @@ func TestLogger(t *testing.T) {
Message: "some other",
Fields: expectedFields,
})
assertLog(t, hook.LastEntry(), expectedLog{
assertLog(t, hook.AllEntries()[2], expectedLog{
Level: "info",
Message: "yeah",
Fields: expectedFields,
})
assertLog(t, hook.LastEntry(), expectedLog{
Level: "info",
Message: "ok",
Fields: map[string]any{},
})
})
})

Expand Down

0 comments on commit 14a97c5

Please sign in to comment.