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

⚠️ log: Initial logr/logrusr implementation #1516

Merged
merged 3 commits into from
Jan 25, 2022

Conversation

justaugustus
Copy link
Member

@justaugustus justaugustus commented Jan 23, 2022

  • Please check if the PR fulfills these requirements
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Continues #1502.
ref: #1273

Signed-off-by: Stephen Augustus [email protected]

  • What is the current behavior? (You can also link to an open issue here)

#1502 implemented a generic logger that wrapped zap. Create a new logger is done by calling log.Logger(log.Level).

  • What is the new behavior (if this is a feature change)?

log.Logger now uses logr, which provides a sane interface and has multiple popular implementations.

From @thockin in #1273 (comment):

Stephen pinged me for a consult, so here I am :)

Opinion: About 1% of apps can actually justify writing logging abstractions, but 90% of us end up doing it because there isn't a (literal or de facto) standard.

I offer you http://github.com/go-logr/logr as that standard. logr defines an API, but not an impl. There are many implementations available (including glog, klog, zap, logrus, and zerolog). Your main package can have full knowledge of the impl, set it up as it likes, and then pass it down to the rest of the app.

EVERYTHING ELSE only needs to know the logr API. The logr package has no external dependencies (and will not grow them, scout's honor), so it is a "safe" thing to depend on. And it's TINY (500 LOC, 3/4 of that is comments). And it has testing implementations and trivial "give me a func() to call" implementations.

The more of us that use it (klog already uses it internally, for example :) the more inertia we build.

Writing log wrappers is a nerd-snipe.

While zapr exists, I opted to choose logrusr as logrus just happens to be used by a few more projects in the ecosystem that I'm familiar with (including Kubernetes Release Engineering logging)

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Yes!

Consumers of functions like:

func CreateGithubRepoClient(ctx context.Context, logger *zap.Logger) clients.RepoClient { ... }

will need to use log.Logger as an argument:

func CreateGithubRepoClient(ctx context.Context, logger *log.Logger) clients.RepoClient { ... }

as well as update log calls from:

ghClient := CreateGithubRepoClient(ctx, logger)
logger.Info(...)

to:

ghClient := CreateGithubRepoClient(ctx, logger)
logger.Zap.Info(...)
  • Other information:

@justaugustus justaugustus temporarily deployed to integration-test January 23, 2022 11:37 Inactive
@github-actions
Copy link

Integration tests success for
[d413eea]
(https://github.com/ossf/scorecard/actions/runs/1735784633)

@justaugustus justaugustus temporarily deployed to integration-test January 23, 2022 11:56 Inactive
@github-actions
Copy link

Integration tests success for
[ab7c620]
(https://github.com/ossf/scorecard/actions/runs/1735816942)

@justaugustus justaugustus temporarily deployed to integration-test January 23, 2022 12:39 Inactive
@github-actions
Copy link

Integration tests success for
[b8fd952]
(https://github.com/ossf/scorecard/actions/runs/1735911390)

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2022

Codecov Report

Merging #1516 (f85ee75) into main (b6cba86) will increase coverage by 0.07%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #1516      +/-   ##
==========================================
+ Coverage   51.25%   51.32%   +0.07%     
==========================================
  Files          68       68              
  Lines        6140     6131       -9     
==========================================
  Hits         3147     3147              
+ Misses       2788     2779       -9     
  Partials      205      205              

log/log.go Outdated Show resolved Hide resolved
@naveensrinivasan
Copy link
Member

If we merge this change then the next release would have to be v5.0.0. This is breaking API.

@justaugustus justaugustus temporarily deployed to integration-test January 24, 2022 21:49 Inactive
@github-actions
Copy link

Integration tests success for
[3ab622a]
(https://github.com/ossf/scorecard/actions/runs/1742343093)

@justaugustus justaugustus temporarily deployed to integration-test January 25, 2022 00:34 Inactive
@github-actions
Copy link

Integration tests success for
[af4b787]
(https://github.com/ossf/scorecard/actions/runs/1742927281)

@justaugustus justaugustus temporarily deployed to integration-test January 25, 2022 00:58 Inactive
@justaugustus
Copy link
Member Author

@naveensrinivasan @azeemshaikh38 -- I think this is ready for review!

@justaugustus justaugustus changed the title ⚠️ [WIP] log: Initial logr/logrusr implementation ⚠️ log: Initial logr/logrusr implementation Jan 25, 2022
@github-actions
Copy link

Integration tests success for
[f85ee75]
(https://github.com/ossf/scorecard/actions/runs/1743003485)

Copy link
Contributor

@azeemshaikh38 azeemshaikh38 left a comment

Choose a reason for hiding this comment

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

This is so much neater, thanks @justaugustus!

go.mod Outdated
@@ -35,6 +37,8 @@ require (
mvdan.cc/sh/v3 v3.4.2
)

// TODO(go.mod): Is there a reason these deps are kept separately from the
Copy link
Contributor

Choose a reason for hiding this comment

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

@naveensrinivasan might know why?

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like they might be related to tools, which is why they got segmented off?
Anyhow, I kept the TODO in and moved them to the top in bba907d, which should cause go mod tidy to update the larger replace block instead.

@azeemshaikh38
Copy link
Contributor

If we merge this change then the next release would have to be v5.0.0. This is breaking API.

True. For now, I think we can merge this in and discuss in this week's meet about how to handle the release version.

...to prevent automatic updates from getting added to the smaller
section.

Signed-off-by: Stephen Augustus <[email protected]>
@justaugustus justaugustus temporarily deployed to integration-test January 25, 2022 16:30 Inactive
@justaugustus
Copy link
Member Author

This is so much neater, thanks @justaugustus!

@azeemshaikh38 -- Happy to help! I just rebased to deconflict w/ main, so once tests pass, this should be good to merge.

@github-actions
Copy link

Integration tests success for
[bba907d]
(https://github.com/ossf/scorecard/actions/runs/1746537081)

Copy link
Member

@naveensrinivasan naveensrinivasan left a comment

Choose a reason for hiding this comment

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

Thanks!

// If the level is not recognized, it defaults to `logrus.InfoLevel` to swallow
// potential configuration errors/typos when specifying log levels.
// https://pkg.go.dev/github.com/sirupsen/logrus#ParseLevel
func ParseLevel(lvl string) logrus.Level {
Copy link
Member

Choose a reason for hiding this comment

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

Could we add some unit tests for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could we add some unit tests for this?

Created #1528 for tracking!

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.

4 participants