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

Add logging developer guideline #5175

Merged
merged 9 commits into from
Dec 22, 2021
Merged

Conversation

timebertt
Copy link
Member

How to categorize this PR?

/area documentation dev-productivity logging
/kind enhancement

What this PR does / why we need it:

In the context of #4251, we are migrating our components from logrus to logr (see #5057 for part 1).
As migrating to a new logging library and also a new logging style (structured logging) brings up a lot of questions and confusion, I proactively try to clarify them in a developer guideline around logging in our components.
Also, this guideline will hopefully bring more consistency into logging in our codebase.

This should be consulted by developers adding new logs or refactoring existing code (like me), as well as reviewers.
I hope that it will be useful for them, so that they don't have to read up on so many things and dig through logging code to figure out how to best write a simple log statement in some controller.

Which issue(s) this PR fixes:
Part of #4251

Special notes for your reviewer:

After "formalizing" the guideline, I went over the code touched by #5057 again and applied it to it. That's also why I'm adding this guideline now, so that I have something to follow along the way as well :)

Also, I cleaned up some "obvious" inconsistencies in the codebase with the guideline already (mainly regarding the capitalization part).
I only touched logr statements for now, as the rest will be touched later on anyways.
Further inconsistencies like e.g. fmt.Sprintf usage in log messages can be cleaned up later on in dedicated PRs.

/squash

Release note:

A developer guideline on logging in Gardener components has been added. Please consult this document as a developer or reviewer to ensure consistency in our logs across the codebase. You can find the document [here](https://github.com/gardener/gardener/blob/master/docs/development/logging.md).

@timebertt timebertt requested a review from a team as a code owner December 16, 2021 13:59
@gardener-robot gardener-robot added needs/review area/dev-productivity Developer productivity related (how to improve development) area/documentation Documentation related area/logging Logging related kind/enhancement Enhancement, improvement, extension size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 16, 2021
@rfranzke
Copy link
Member

/assign

@timebertt
Copy link
Member Author

Fixed the unit tests by adapting them to the changes in the last commit.

Copy link
Member

@rfranzke rfranzke left a comment

Choose a reason for hiding this comment

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

Very nice!

docs/development/logging.md Show resolved Hide resolved
docs/development/logging.md Outdated Show resolved Hide resolved
docs/development/logging.md Outdated Show resolved Hide resolved
ialidzhikov
ialidzhikov previously approved these changes Dec 21, 2021
Copy link
Member

@ialidzhikov ialidzhikov left a comment

Choose a reason for hiding this comment

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

/lgtm
/squash

@timebertt
Copy link
Member Author

Thanks for all your feedback!
All assigned reviewers have already approved / reviewed. Hence, I propose to merge this tomorrow if nobody else wants to review / is assigned to this PR.

Copy link
Contributor

@stoyanr stoyanr left a comment

Choose a reason for hiding this comment

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

I also like it very much. I also "tested" it by switching to logr.Logger in #5150, and it "worked" fine (but I still needed some advice from @timebertt, see below). Still, I have a few comments that I consider relatively important.

docs/development/logging.md Outdated Show resolved Hide resolved
docs/development/logging.md Outdated Show resolved Hide resolved
@timebertt
Copy link
Member Author

@stoyanr thanks for your feedback as well. I addressed your comments in new commits. PTAL :)

@timebertt
Copy link
Member Author

/retest

Copy link
Contributor

@stoyanr stoyanr left a comment

Choose a reason for hiding this comment

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

@timebertt Thanks for addressing my suggestions!
/lgtm

@timebertt timebertt merged commit 963f29c into gardener:master Dec 22, 2021
@timebertt timebertt deleted the logging-guideline branch December 22, 2021 14:54
krgostev pushed a commit to krgostev/gardener that referenced this pull request Apr 21, 2022
* Add logging developer guideline

* Follow logging guideline in already refactored controllers

* Consistently capitalize error logs

* Consistently capitalize info logs

* Address review comments

* Address more feedback

* Clarify the level mapping

* Discourage use of kutil.ObjectName

* Add some notes about the migration
krgostev pushed a commit to krgostev/gardener that referenced this pull request Jul 5, 2022
* Add logging developer guideline

* Follow logging guideline in already refactored controllers

* Consistently capitalize error logs

* Consistently capitalize info logs

* Address review comments

* Address more feedback

* Clarify the level mapping

* Discourage use of kutil.ObjectName

* Add some notes about the migration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dev-productivity Developer productivity related (how to improve development) area/documentation Documentation related area/logging Logging related kind/enhancement Enhancement, improvement, extension size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants