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(logging): using new package containing logrus.Logger instead of global scope logrus (closes #583) (#699, @Shanduur) #699

Merged
merged 6 commits into from
Aug 18, 2021

Conversation

shanduur
Copy link
Contributor

@shanduur shanduur commented Aug 2, 2021

What

This PR is intended to close issue #583 . New package logger was introduced and all usages of logrus.Something were replaced with l.Log().Something, e.g.:

-import log "github.com/sirupsen/logrus"
+import l "github.com/rancher/k3d/v4/logger"

/* ... */
-	log.Errorf(/* ... */
+	l.Log().Errorf(/* ... */

Why

Due to the #583 .

Implications

It does not affect the behavior of the CLI, but it can affect all 3rd party users of k3d packages. As the global scope logrus is no longer used, it can create mismatch between log level of k3d packages and other packages importing k3d packages using global scope logrus.

@shanduur shanduur changed the title [Enhancement] using new package containing logrus.Logger instead of global scope logrus (closes #583) feat(logging): using new package containing logrus.Logger instead of global scope logrus (closes #583) Aug 2, 2021
@iwilltry42 iwilltry42 added this to the v5.0.0 milestone Aug 12, 2021
@iwilltry42 iwilltry42 self-requested a review August 16, 2021 12:42
@iwilltry42
Copy link
Member

iwilltry42 commented Aug 16, 2021

Hi @shanduur , thanks for opening this PR!
That's a great change, that will also solve some issues I faced recently, where the docker dependency overwrote log settings of k3d, as both used the global context logrus instance 🙄
However, this will go into v5.0.0... any chance you could re-do this from main-v5 branch? 🤔

EDIT: I changed the PR base branch to main-v5 already and obviously we run into some merge conflicts now. Also I guess, basing it off of this new branch, some changes will be missing from new files 🤔

EDIT 2: if that's too much work and you don't have the time to do it, I can try my hand on porting your changes accordingly. Let me know 👍

@iwilltry42 iwilltry42 changed the base branch from main to main-v5 August 16, 2021 12:45
@shanduur
Copy link
Contributor Author

I'll fix that!

Signed-off-by: Mateusz Urbanek <mateusz.urbanek.98@gmail.com>
@shanduur
Copy link
Contributor Author

@iwilltry42 could you look at failed tests? I am not sure if this is something broken by me.

Copy link
Member

@iwilltry42 iwilltry42 left a comment

Choose a reason for hiding this comment

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

I have to admit.. that was a quite repetitive review 😂
Thanks a lot for your effort in this @shanduur !

I have some change requests though, which are rather small and most result from the search-replace flow I guess.

UPDATE: committed the suggestions now, so the PR should be ready to merge once the tests pass ✔️

docs/usage/guides/calico.yaml Outdated Show resolved Hide resolved
docs/static/js/asciinema-player.js Outdated Show resolved Hide resolved
} else if pluginFound {
os.Exit(0)
}
}
}
if err := cmd.Execute(); err != nil {
log.Fatalln(err)
l.Log().Fatalln(err)
}
}

// initLogging initializes the logger
func initLogging() {
Copy link
Member

Choose a reason for hiding this comment

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

TODO for later (no need to do it in this PR): move this to the logger package with functions to set k3d defaults and proper config structs.
I guess this would make sense to have it defined in pkg/ instead of the CLI (cmd/) path/package.

@@ -175,7 +175,7 @@ func GetDockerClient() (*client.Client, error) {
}

newClientOpts := flags.NewClientOptions()
newClientOpts.Common.LogLevel = log.GetLevel().String() // this is needed, as the following Initialize() call will set a new log level on the global logrus instance
newClientOpts.Common.LogLevel = l.Log().GetLevel().String() // this is needed, as the following Initialize() call will set a new log level on the global logrus instance
Copy link
Member

Choose a reason for hiding this comment

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

I guess this could be dropped now, as k3d itself doesn't use the global logrus instance anymore.. but it's not that important and maybe it could even be useful to cascade the log level down to the docker client 🤔

tools/cmd/image.go Outdated Show resolved Hide resolved
tools/main.go Outdated Show resolved Hide resolved
@iwilltry42 iwilltry42 self-requested a review August 18, 2021 10:19
@iwilltry42 iwilltry42 changed the title feat(logging): using new package containing logrus.Logger instead of global scope logrus (closes #583) feat(logging): using new package containing logrus.Logger instead of global scope logrus (closes #583) (#699, @Shanduur) Aug 18, 2021
@iwilltry42 iwilltry42 merged commit 917c19e into k3d-io:main-v5 Aug 18, 2021
@iwilltry42
Copy link
Member

Thanks a lot for the time and effort @shanduur :)

@shanduur
Copy link
Contributor Author

@all-contributors please add @shanduur for code

@allcontributors
Copy link
Contributor

@shanduur

I've put up a pull request to add @shanduur! 🎉

@iwilltry42 iwilltry42 mentioned this pull request Aug 18, 2021
12 tasks
FedericoAntoniazzi added a commit to FedericoAntoniazzi/k3d that referenced this pull request Aug 18, 2021
FedericoAntoniazzi added a commit to FedericoAntoniazzi/k3d that referenced this pull request Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Better to use logrus.New to replace the global scope logrus
2 participants