-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* loglevel-string
- Loading branch information
Showing
11 changed files
with
159 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,4 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
.vscode | ||
.theia | ||
tmp/ | ||
bin/ |
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 |
---|---|---|
|
@@ -8,3 +8,8 @@ cover: | |
checks: | ||
hack/checks.sh | ||
|
||
misspell: | ||
hack/misspell.sh | ||
|
||
gocyclo: | ||
hack/gocyclo.sh |
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,11 @@ | ||
#!/bin/bash | ||
cd $(dirname $0)/../ | ||
|
||
which gocyclo || go install github.com/fzipp/gocyclo/cmd/gocyclo@latest | ||
|
||
gocyclo -over 15 . | ||
if [[ $? != 0 ]]; then | ||
echo "❌ FAIL" | ||
exit 1 | ||
fi | ||
echo "✔️ OK" |
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,11 @@ | ||
#!/bin/bash | ||
cd $(dirname $0)/.. | ||
|
||
[ -f ./bin/misspell ] || curl -L https://git.io/misspell | bash | ||
|
||
find ./ -type f -name '*.*' | xargs ./bin/misspell -error | ||
if [[ $? != 0 ]]; then | ||
echo "❌ FAIL - misspell found" | ||
exit 1 | ||
fi | ||
echo "✔️ OK - misspell not found" |
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
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,26 @@ | ||
package logger | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type Level logrus.Level | ||
|
||
const ( | ||
PanicLevel Level = Level(logrus.PanicLevel) | ||
FatalLevel Level = Level(logrus.FatalLevel) | ||
ErrorLevel Level = Level(logrus.ErrorLevel) | ||
WarnLevel Level = Level(logrus.WarnLevel) | ||
InfoLevel Level = Level(logrus.InfoLevel) | ||
DebugLevel Level = Level(logrus.DebugLevel) | ||
TraceLevel Level = Level(logrus.TraceLevel) | ||
) | ||
|
||
func (level Level) String() string { | ||
return logrus.Level(level).String() | ||
} | ||
|
||
func ParseLevel(lvl string) (Level, error) { | ||
level, err := logrus.ParseLevel(lvl) | ||
return Level(level), err | ||
} |
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,66 @@ | ||
package logger | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestString(t *testing.T) { | ||
testCases := []struct { | ||
logLevel Level | ||
want string | ||
}{ | ||
{PanicLevel, "panic"}, | ||
{FatalLevel, "fatal"}, | ||
{ErrorLevel, "error"}, | ||
{WarnLevel, "warning"}, | ||
{InfoLevel, "info"}, | ||
{DebugLevel, "debug"}, | ||
{TraceLevel, "trace"}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run("", func(t *testing.T) { | ||
got := tc.logLevel.String() | ||
require.Equal(t, tc.want, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestParseLevel(t *testing.T) { | ||
testCases := []struct { | ||
levelString string | ||
want Level | ||
wantError string | ||
}{ | ||
{"panic", PanicLevel, ``}, | ||
{"PANIC", PanicLevel, ``}, | ||
{"fatal", FatalLevel, ``}, | ||
{"FATAL", FatalLevel, ``}, | ||
{"error", ErrorLevel, ``}, | ||
{"ERROR", ErrorLevel, ``}, | ||
{"warn", WarnLevel, ``}, | ||
{"WARN", WarnLevel, ``}, | ||
{"warning", WarnLevel, ``}, | ||
{"WARNING", WarnLevel, ``}, | ||
{"info", InfoLevel, ``}, | ||
{"INFO", InfoLevel, ``}, | ||
{"debug", DebugLevel, ``}, | ||
{"DEBUG", DebugLevel, ``}, | ||
{"trace", TraceLevel, ``}, | ||
{"TRACE", TraceLevel, ``}, | ||
{"invalid", PanicLevel, `not a valid logrus Level: "invalid"`}, | ||
{"foo", PanicLevel, `not a valid logrus Level: "foo"`}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run("", func(t *testing.T) { | ||
got, err := ParseLevel(tc.levelString) | ||
if tc.wantError == "" { | ||
require.NoError(t, err) | ||
} else { | ||
require.EqualError(t, err, tc.wantError) | ||
} | ||
require.Equal(t, tc.want, got) | ||
}) | ||
} | ||
} |