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

Support debug mode #90

Open
majori opened this issue Mar 11, 2024 · 4 comments
Open

Support debug mode #90

majori opened this issue Mar 11, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@majori
Copy link
Member

majori commented Mar 11, 2024

Currently we already have a global flag --debug, but it does not do anything. Enabling debug mode should cause more verbose logging

@majori majori added enhancement New feature or request good first issue Good for newcomers labels Mar 11, 2024
@vesse
Copy link
Collaborator

vesse commented Jun 11, 2024

What kind of stuff you had in mind here? Most(?) of the current output seems to be Cobra cmd prints but using that deeper in the engine would require passing it forward which would not be cool, and some output comes from fmt directly.

There's golang log package and then naturally multiple loggers offering all kinds of features that could make sense for having configurable log level and other options. Some examples:

And then one can implement some kind of DIY logger of course.

@majori
Copy link
Member Author

majori commented Jun 11, 2024

I haven't actually thought about the logging library that much, but I think we can start with the Go's log package. My idea was that on root CLI function we hook the logger to the cmd output with log.SetOutput(cmd.OutOrStdout()) and set log.SetPrefix("[DEBUG]: "). Then just start using the log.Printf(...).

@majori
Copy link
Member Author

majori commented Jun 12, 2024

My initial though was just conditionally run the log.Print like if opts.Debug { log.Print(...) } but I realized that is dumb. So we need to set the log.SetOutput(cmd.OutOrStdout()) conditionally, and otherwise set the logger output to "/dev/null". This might require setting the Common options to root level and passing them to subcommands.

@vesse
Copy link
Collaborator

vesse commented Jun 12, 2024

Yeah using if would be dumb 😄 Using conditionally set output seems fine if you you don't see a need more fine-grained logging. With a proper logger the code would just log stuff with different level and flags would configure log output based on the levels, but this might be an overkill for the need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants