Skip to content
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

Merged
merged 10 commits into from
Feb 24, 2023

Conversation

gozeloglu
Copy link
Contributor

@gozeloglu gozeloglu commented Feb 22, 2023

With this PR, ParseLevel function is added. It converts the level in string type to Level type. Default level is set to INFO level.

log_test.go Outdated Show resolved Hide resolved
log_test.go Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
log.go Outdated Show resolved Hide resolved
Gökhan Özeloğlu added 4 commits February 23, 2023 00:21
* 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>
@gozeloglu gozeloglu force-pushed the add-log-lvl-env-feat branch from 395864a to 06f692b Compare February 22, 2023 21:23
* Replace swich-case blocks with `ParseLevel` function in `WithLevelFromString`.

Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
@gozeloglu gozeloglu requested review from caarlos0 and aymanbagabas and removed request for caarlos0 and aymanbagabas February 22, 2023 21:28
options.go Outdated Show resolved Hide resolved
Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
log_test.go Outdated Show resolved Hide resolved
options.go Outdated Show resolved Hide resolved
@caarlos0 caarlos0 changed the title Read log level from env var feat: parse level from string Feb 23, 2023
log_test.go Outdated Show resolved Hide resolved
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) {
Copy link
Member

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

log_test.go Outdated Show resolved Hide resolved
@aymanbagabas
Copy link
Member

@gozeloglu could you squash the commits into a single one? feat(level): parse level from string

Gökhan Özeloğlu added 2 commits February 23, 2023 23:15
* 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>
@gozeloglu
Copy link
Contributor Author

@gozeloglu could you squash the commits into a single one? feat(level): parse level from string

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
Comment on lines 66 to 70
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.

level_test.go Outdated
testCases := []struct {
name string
level string
envVarLevel string
Copy link
Member

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
Comment on lines 65 to 72
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)
Copy link
Member

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:

Suggested change
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))

Gökhan Özeloğlu added 2 commits February 24, 2023 08:37
Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Copy link
Member

@caarlos0 caarlos0 left a 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
Copy link

codecov bot commented Feb 24, 2023

Codecov Report

Merging #11 (72bc69e) into main (6e4f0e1) will increase coverage by 0.37%.
The diff coverage is 100.00%.

@@            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              
Impacted Files Coverage Δ
level.go 92.85% <100.00%> (+35.71%) ⬆️
text.go 45.93% <0.00%> (-0.82%) ⬇️
styles.go 0.00% <0.00%> (ø)
examples/app/main.go
examples/styles/styles.go 0.00% <0.00%> (ø)
examples/app/app.go 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@gozeloglu
Copy link
Contributor Author

just need to update the PR description, other than that, LGTM!

Thanks 🙏

I updated it. Thanks.

Copy link
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks @gozeloglu!

@aymanbagabas aymanbagabas merged commit baccac6 into charmbracelet:main Feb 24, 2023
@gozeloglu gozeloglu deleted the add-log-lvl-env-feat branch February 27, 2023 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants