Skip to content

Commit

Permalink
Log improvements (#819)
Browse files Browse the repository at this point in the history
* add more log levels
* add test to check new code added
  • Loading branch information
emmanuelm41 committed Sep 30, 2021
1 parent 601871b commit 0cf33c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const (
LogInfo
// LogDebug sets the logging verbosity to debug
LogDebug
// LogWarn sets the logging verbosity to warn
LogWarn
// LogError sets the logging verbosity to error
LogError
// LogAll sets the logging verbosity to all
LogAll
)

const logStackDepth = 6
Expand Down Expand Up @@ -76,6 +82,12 @@ func NewLogger(l log.Logger, level int) Logger {
opt = lvl.AllowInfo()
case LogDebug:
opt = lvl.AllowDebug()
case LogWarn:
opt = lvl.AllowWarn()
case LogError:
opt = lvl.AllowError()
case LogAll:
opt = lvl.AllowAll()
default:
panic("unknown log level")
}
Expand Down
9 changes: 9 additions & 0 deletions log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestLoggerKit(t *testing.T) {
Debug
Warn
Error
All
None
)

type logTest struct {
Expand All @@ -36,6 +38,9 @@ func TestLoggerKit(t *testing.T) {
var tests = []logTest{
{nil, nil, Info, "hello", o("hello")},
{nil, lvl.AllowInfo(), Debug, "hello", nil},
{nil, lvl.AllowError(), Error, "hello", o("hello")},
{nil, lvl.AllowAll(), All, "hello", o("hello")},
{nil, lvl.AllowNone(), None, "hello", nil},
{w("yard", "bird"), lvl.AllowWarn(), Warn, "hello", o("yard", "bird", "hello")},
}

Expand All @@ -61,6 +66,10 @@ func TestLoggerKit(t *testing.T) {
logging = kit.Warn
case Error:
logging = kit.Error
case All:
logging = kit.Info
case None:
logging = kit.Info
default:
t.FailNow()
}
Expand Down

0 comments on commit 0cf33c1

Please sign in to comment.