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 flag for setting log levels and log errors for debugging. #139

Merged
merged 3 commits into from
Oct 30, 2021

Conversation

YrrepNoj
Copy link
Contributor

@YrrepNoj YrrepNoj commented Oct 28, 2021

Added a global flag (works for any subcommand) for setting the log level of logrus. This gets applied to a local utility logger that all the other packages will use. Having the local utility logger buys us the ability to set it once and forget about it instead of having to set the log level for every package. This also means we can have universal styling/formatting across all of our packages if that's something we care about in the future.

This PR also logs all errors to Debug to make it easy to figure out what's happening when something happens to go wrong. I chose Debug mode since we probably don't want that filling the console all the time, but at the same time errors should be rare and maybe we want to know exactly what happened whenever it happens so I can also see an argument for using Error mode instead..

@YrrepNoj YrrepNoj linked an issue Oct 28, 2021 that may be closed by this pull request
@YrrepNoj YrrepNoj self-assigned this Oct 28, 2021
@@ -36,4 +43,5 @@ func Execute() {

func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.PersistentFlags().StringVarP(&zarfLogLevel, "log-level", "l", "info", "Log level when runnning Zarf. Valid options are: debug, info, warn, error, fatal")
Copy link
Contributor Author

@YrrepNoj YrrepNoj Oct 28, 2021

Choose a reason for hiding this comment

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

This sets the default logging level to info (which is what logrus would use if we didn't specify anything else). The way it is currently written would have this interaction:
./zarf init --log-level error -> Runs Zarf with the log level set to error
./zarf deploy. -> Runs Zarf with the log level set to info

Which is what I would expect it to do but I could see others expecting it to stay in error mode. Does anyone think this is something we might want to do?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the default log level should be the quieter one, with the ability to make it more noisy if you want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

info is the default the loggrus uses so it's what we're currently using right now. I can easily make it warn though.

@jeff-mccoy
Copy link
Contributor

So I do have concerns with just doing a generic log wrapper here, I don't see a compelling reason to make this change across all the files when you could just leave the setLevel() in the Cobra root.cmd, as used here: https://github.com/sirupsen/logrus/blob/master/entry.go#L55.

I just tested that and confirmed that setting in root.cmd properly persists into other imports of logrus in the CLI without a wrapper.

@YrrepNoj
Copy link
Contributor Author

YrrepNoj commented Oct 29, 2021

So I do have concerns with just doing a generic log wrapper here, I don't see a compelling reason to make this change across all the files when you could just leave the setLevel() in the Cobra root.cmd, as used here: https://github.com/sirupsen/logrus/blob/master/entry.go#L55.

I just tested that and confirmed that setting in root.cmd properly persists into other imports of logrus in the CLI without a wrapper.

woah.. I don't know why I was so certain that setting the log level will only affect the logrus instance for that current package.

@YrrepNoj YrrepNoj closed this Oct 29, 2021
@YrrepNoj YrrepNoj reopened this Oct 29, 2021
@jeff-mccoy
Copy link
Contributor

So I do have concerns with just doing a generic log wrapper here, I don't see a compelling reason to make this change across all the files when you could just leave the setLevel() in the Cobra root.cmd, as used here: https://github.com/sirupsen/logrus/blob/master/entry.go#L55.
I just tested that and confirmed that setting in root.cmd properly persists into other imports of logrus in the CLI without a wrapper.

woah.. I don't know why I was so certain that setting the log level will only affect the logrus instance for that current package.

I actually wasn't sure either and the docs aren't totally clear so had to test it myself.....and what you didn't isn't wrong, I just don't think we need to abstract the logger yet like that.

@jeff-mccoy
Copy link
Contributor

random ?, does logrus.Debug give us any sort of stack trace as well?

@jeff-mccoy
Copy link
Contributor

/test all

@jeff-mccoy jeff-mccoy merged commit 5825443 into master Oct 30, 2021
@jeff-mccoy jeff-mccoy deleted the feature/specifying-log-level branch October 30, 2021 05:47
jeff-mccoy pushed a commit that referenced this pull request Feb 8, 2022
Noxsios pushed a commit that referenced this pull request Mar 8, 2023
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.

Ability to specify log level
3 participants