-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix: still warn on zero verbosity #68
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the problem that
cfg.Verbosity
is never set, so defaults to0
and thereforeEnableConsole == false
? Is there a way that this configuration could be consolidated to just be based on a verbosity number instead of 3 distinct settings of verbosity, quiet, and level?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the problem. So if there's no TTY and there's no verbosity, there's nowhere for
log.Warn
outputs to go, becauseEnableConsole: false
will cause the underlying writer to beio.Discard
.I don't think it can be simplified beyond this. We want
-q
but a log file and a verbosity set in the environment to still write to the environment I think? I'm not sure I understand your suggestion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not suggesting to change any of the exposed options but rather make the options determine one specific verbosity level, and base all logging configuration on that. It looks like we have a function to do that: https://github.com/anchore/clio/blob/main/logging.go#L133 -- this takes all 3 options into consideration and returns a single logging level. We could modify this function to use the result of that function as the logging level, where anywhere we use quiet, instead we use
levelFromSelectLevel != logger.Disabled
or something like that, and we use that level to setLevel:
below, etc.In fact, I'm not entirely sure why the
selectLevel()
function is modifying the configuration, it should probably not do that and instead just get called inPostLoad
only to validate the options, then later in this function to get the effective logging levelThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a giant TODO in it:
clio/logging.go
Lines 140 to 143 in ceccbdd
Is that something we should be addressing in this PR? Is there any issue for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO actually seems to be saying we don't want to collapse the amount of options here.
I don't think we can sensibly do that, because we have 4 independent dimensions of input:
quiet
- don't do fancy terminal UI or log to the terminal-v
/-vv
raise the level of the logger, regardless of where it printslogfile
- change the logger, whatever its level is, to append to this path instead of stderr, regardless of whether--quiet
was passed or a TTY is present.In other words, something like
SYFT_LOG_FILE=/tmp/log.txt syft --quiet -vvv ...
should be a valid command, that should append trace logs of/tmp/log.txt
and not do any fancy TUI stuff or log to stdout or stderr.Does that make sense? Maybe we should have a discussion about how these options should interact, then revisit this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the longer discussion about logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is the topic I meant to link to.