-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull out GetLoglevel to a separate package
Add option to set loglevel while initializing plugin config
- Loading branch information
1 parent
cda8e3c
commit 27bc52c
Showing
6 changed files
with
72 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package logger | ||
|
||
import ( | ||
"strings" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// GetLoglevel sets the loglevel to the kind of log asked for. | ||
func GetLoglevel(level string) log.Level { | ||
switch strings.ToLower(level) { | ||
case log.WarnLevel.String(): | ||
return log.WarnLevel | ||
case log.DebugLevel.String(): | ||
return log.DebugLevel | ||
case log.TraceLevel.String(): | ||
return log.TraceLevel | ||
case log.FatalLevel.String(): | ||
return log.FatalLevel | ||
case log.ErrorLevel.String(): | ||
return log.ErrorLevel | ||
default: | ||
return log.InfoLevel | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package logger_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nikhilsbhat/gocd-sdk-go/pkg/logger" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getLoglevel(t *testing.T) { | ||
t.Run("should return warn level", func(t *testing.T) { | ||
actual := logger.GetLoglevel("warning") | ||
assert.Equal(t, log.WarnLevel, actual) | ||
}) | ||
t.Run("should return trace level", func(t *testing.T) { | ||
actual := logger.GetLoglevel("trace") | ||
assert.Equal(t, log.TraceLevel, actual) | ||
}) | ||
t.Run("should return debug level", func(t *testing.T) { | ||
actual := logger.GetLoglevel("debug") | ||
assert.Equal(t, log.DebugLevel, actual) | ||
}) | ||
t.Run("should return fatal level", func(t *testing.T) { | ||
actual := logger.GetLoglevel("fatal") | ||
assert.Equal(t, log.FatalLevel, actual) | ||
}) | ||
t.Run("should return error level", func(t *testing.T) { | ||
actual := logger.GetLoglevel("error") | ||
assert.Equal(t, log.ErrorLevel, actual) | ||
}) | ||
t.Run("should return error level", func(t *testing.T) { | ||
actual := logger.GetLoglevel("") | ||
assert.Equal(t, log.InfoLevel, actual) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters