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

replace log with zap #55

Merged
merged 3 commits into from
May 30, 2022
Merged

replace log with zap #55

merged 3 commits into from
May 30, 2022

Conversation

glightfoot
Copy link
Contributor

In #52, it was suggested to try Zap instead of logrus. While the performance difference is inconsequential, I threw this together to show what it would look like. The structured logging in Zap isn't really useful since this is just a command line tool, and zap seems to always format fields as JSON.

Like with logrus, all logs are sent to stderr.

Here's some sample output:

$ dist/gci print pkg/gci/format.go --debug >/dev/null 
2022-03-10T14:20:04.266-0800    DEBUG   gci/gci.go:112  Loaded File: pkg/gci/format.go
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:48        Parsed imports in file: ["bytes" "fmt" "strings" "github.com/daixiang0/gci/pkg/constants" "github.com/daixiang0/gci/pkg/gci/imports" "github.com/daixiang0/gci/pkg/gci/sections" "github.com/daixiang0/gci/pkg/gci/specificity" "go.uber.org/zap"]
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "bytes" to section Standard
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "fmt" to section Standard
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "strings" to section Standard
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "github.com/daixiang0/gci/pkg/constants" to section Default
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "github.com/daixiang0/gci/pkg/gci/imports" to section Default
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "github.com/daixiang0/gci/pkg/gci/sections" to section Default
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "github.com/daixiang0/gci/pkg/gci/specificity" to section Default
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:72        Matched import "go.uber.org/zap" to section Default
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:82        Formatting section Standard with imports: ["bytes" "fmt" "strings"]
2022-03-10T14:20:04.266-0800    DEBUG   gci/format.go:82        Formatting section Default with imports: ["github.com/daixiang0/gci/pkg/constants" "github.com/daixiang0/gci/pkg/gci/imports" "github.com/daixiang0/gci/pkg/gci/sections" "github.com/daixiang0/gci/pkg/gci/specificity" "go.uber.org/zap"]

@glightfoot glightfoot closed this Mar 16, 2022
@daixiang0 daixiang0 reopened this Mar 18, 2022
@daixiang0 daixiang0 marked this pull request as ready for review March 18, 2022 10:23
@daixiang0
Copy link
Owner

Please sign commits, sorry for this switch.

@glightfoot
Copy link
Contributor Author

I added a log package so the zap logger doesn't replace any globals in case someone is using gci as a package

glightfoot and others added 3 commits March 18, 2022 08:11
Signed-off-by: Greg Lightfoot <glightfoot3@gmail.com>
Signed-off-by: Greg Lightfoot <glightfoot3@gmail.com>
Signed-off-by: Greg Lightfoot <glightfoot3@gmail.com>
@daixiang0
Copy link
Owner

@ldez is zap good for you?

@daixiang0 daixiang0 merged commit 262c6a3 into daixiang0:master May 30, 2022
daixiang0 pushed a commit that referenced this pull request May 30, 2022
* replace log with zap

Signed-off-by: Greg Lightfoot <glightfoot3@gmail.com>

* add log package to not replace globals

Signed-off-by: Greg Lightfoot <glightfoot3@gmail.com>

* add a func to allow setting the gci logger

Signed-off-by: Greg Lightfoot <glightfoot3@gmail.com>
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.

2 participants