-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: parse level from string #11
feat: parse level from string #11
Conversation
* Fixes charmbracelet#9. * With these changes, the log level will be able to read from the env var with `LOG_LEVEL` key. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
* Update .gitignore. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
* `readLevelFromEnv` function is removed. * Tests updated. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
* This function converts string to Level type. * Unit test implemented. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
395864a
to
06f692b
Compare
* Replace swich-case blocks with `ParseLevel` function in `WithLevelFromString`. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
log_test.go
Outdated
@@ -2,20 +2,23 @@ package log | |||
|
|||
import ( | |||
"bytes" | |||
"os" | |||
"strings" | |||
"testing" | |||
|
|||
"github.com/stretchr/testify/assert" | |||
) | |||
|
|||
func TestSubLogger(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the changes here should be in their own separate test TestParseLevel
@gozeloglu could you squash the commits into a single one? |
* Revert changes in `log_test.go`. * Update test cases in `level_test.go`. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Cannot you squash the commit when you merge the PR? I think it is possible. If I have to do that, I need to search a little bit. I don't know the command(s) for squashing the commits. |
level_test.go
Outdated
if tc.envVarLevel != "" { | ||
t.Setenv("LOG_LEVEL", tc.envVarLevel) | ||
lvl = ParseLevel(os.Getenv("LOG_LEVEL")) | ||
} else { | ||
lvl = ParseLevel(tc.level) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
level_test.go
Outdated
testCases := []struct { | ||
name string | ||
level string | ||
envVarLevel string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed anymore, as per previous comment
level_test.go
Outdated
var lvl Level | ||
if tc.envVarLevel != "" { | ||
t.Setenv("LOG_LEVEL", tc.envVarLevel) | ||
lvl = ParseLevel(os.Getenv("LOG_LEVEL")) | ||
} else { | ||
lvl = ParseLevel(tc.level) | ||
} | ||
assert.Equal(t, tc.expLevel, lvl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to test envs anymore, as the main lib does nothing with them
this can be:
var lvl Level | |
if tc.envVarLevel != "" { | |
t.Setenv("LOG_LEVEL", tc.envVarLevel) | |
lvl = ParseLevel(os.Getenv("LOG_LEVEL")) | |
} else { | |
lvl = ParseLevel(tc.level) | |
} | |
assert.Equal(t, tc.expLevel, lvl) | |
assert.Equal(t, tc.expLevel, ParseLevel(tc.level)) |
Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just need to update the PR description, other than that, LGTM!
Thanks 🙏
Codecov Report
@@ Coverage Diff @@
## main #11 +/- ##
==========================================
+ Coverage 51.02% 51.40% +0.37%
==========================================
Files 22 23 +1
Lines 684 714 +30
==========================================
+ Hits 349 367 +18
- Misses 319 331 +12
Partials 16 16
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
I updated it. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks @gozeloglu!
With this PR,
ParseLevel
function is added. It converts the level in string type toLevel
type. Default level is set toINFO
level.