VOL-2356 Change log.V() to use a typed LogLevel
Change-Id: I1fb61eb8ffbca9b9436e90a1547a59dad1f27029
diff --git a/pkg/log/log.go b/pkg/log/log.go
index 07e5830..69e22a4 100644
--- a/pkg/log/log.go
+++ b/pkg/log/log.go
@@ -108,7 +108,7 @@
Warningf(string, ...interface{})
// V reports whether verbosity level l is at least the requested verbose level.
- V(l int) bool
+ V(l LogLevel) bool
//Returns the log level of this specific logger
GetLogLevel() LogLevel
@@ -643,8 +643,8 @@
}
// V reports whether verbosity level l is at least the requested verbose level.
-func (l logger) V(level int) bool {
- return l.parent.Core().Enabled(logLevelToLevel(LogLevel(level)))
+func (l logger) V(level LogLevel) bool {
+ return l.parent.Core().Enabled(logLevelToLevel(level))
}
// GetLogLevel returns the current level of the logger
@@ -778,7 +778,7 @@
}
// V reports whether verbosity level l is at least the requested verbose level.
-func V(level int) bool {
+func V(level LogLevel) bool {
return getPackageLevelLogger().V(level)
}
diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go
index 84a91d1..be65b02 100644
--- a/pkg/log/log_test.go
+++ b/pkg/log/log_test.go
@@ -17,7 +17,6 @@
import (
"github.com/stretchr/testify/assert"
- "google.golang.org/grpc/grpclog"
"testing"
)
@@ -38,7 +37,7 @@
SetAllLogLevel(LogLevel(minimumLevel))
var success bool
for i := 0; i < 5; i++ {
- success = testLogger.V(i)
+ success = testLogger.V(LogLevel(i))
if i == 1 && minimumLevel == 2 {
// TODO: Update the test when a new version of Zap logger is available. It has a bug with that
// specific combination
@@ -69,13 +68,6 @@
assert.NotNil(t, testLogger)
}
-func TestUseAsGrpcLoggerV2(t *testing.T) {
- var grpcLogger grpclog.LoggerV2
- thisLogger, _ := AddPackage(JSON, ErrorLevel, nil)
- grpcLogger = thisLogger
- assert.NotNil(t, grpcLogger)
-}
-
func TestUpdateLogLevel(t *testing.T) {
// Let's create a bunch of logger each with a separate package
myLoggers := make(map[string]Logger)
@@ -84,17 +76,17 @@
myLoggers[name], _ = AddPackage(JSON, ErrorLevel, nil, []string{name}...)
}
//Test updates to log levels
- levels := []int{0, 1, 2, 3, 4}
+ levels := []LogLevel{DebugLevel, InfoLevel, WarnLevel, ErrorLevel, FatalLevel}
for _, expectedLevel := range levels {
for _, name := range pkgNames {
- SetPackageLogLevel(name, LogLevel(expectedLevel))
+ SetPackageLogLevel(name, expectedLevel)
l, err := GetPackageLogLevel(name)
assert.Nil(t, err)
- assert.Equal(t, l, LogLevel(expectedLevel))
+ assert.Equal(t, l, expectedLevel)
// Get the package log level by invoking the specific logger created for this package
// This is a less expensive operation that the GetPackageLogLevel() request
level := myLoggers[name].GetLogLevel()
- assert.Equal(t, level, LogLevel(expectedLevel))
+ assert.Equal(t, level, expectedLevel)
// Check the verbosity level
for _, level := range levels {
toDisplay := myLoggers[name].V(level)