Skip to content

Commit

Permalink
Fix logrus verbosity level checker (#369)
Browse files Browse the repository at this point in the history
* fix verbosity checker

* add test for verbosity checker
  • Loading branch information
kochurovro authored Dec 1, 2020
1 parent 61b061e commit 83ed827
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logging/logrus/grpclogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ type logrusGrpcLoggerV2 struct {
}

func (l *logrusGrpcLoggerV2) V(level int) bool {
return int(l.Level) >= level
return l.Logger.IsLevelEnabled(logrus.Level(level))
}
71 changes: 71 additions & 0 deletions logging/logrus/grpclogger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package grpc_logrus

import (
"testing"

"github.com/sirupsen/logrus"
)

func Test_logrusGrpcLoggerV2_V(t *testing.T) {
tests := []struct {
name string
setupLevel logrus.Level
inLevel logrus.Level
want bool
}{
{
name: "WarnLevel setup when we have WarnLevel msg should return TRUE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.WarnLevel,
want: true,
},
{
name: "WarnLevel setup when we have ErrorLevel msg should return TRUE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.ErrorLevel,
want: true,
},
{
name: "WarnLevel setup when we have InfoLevel msg should return FALSE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.InfoLevel,
want: false,
},
{
name: "WarnLevel setup when we have DebugLevel msg should return FALSE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.DebugLevel,
want: false,
},
{
name: "WarnLevel setup when we have TraceLevel msg should return FALSE",
setupLevel: logrus.WarnLevel,
inLevel: logrus.TraceLevel,
want: false,
},
{
name: "TraceLevel setup when we have WarnLevel msg should return TRUE",
setupLevel: logrus.TraceLevel,
inLevel: logrus.WarnLevel,
want: true,
},
{
name: "TraceLevel setup when we have TraceLevel msg should return TRUE",
setupLevel: logrus.TraceLevel,
inLevel: logrus.TraceLevel,
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lr := logrus.New()
lr.SetLevel(tt.setupLevel)

l := &logrusGrpcLoggerV2{logrus.NewEntry(lr)}

if got := l.V(int(tt.inLevel)); got != tt.want {
t.Errorf("V() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 83ed827

Please sign in to comment.