-
Notifications
You must be signed in to change notification settings - Fork 908
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 cli debugging #4617
Fix cli debugging #4617
Conversation
@@ -27,12 +27,6 @@ | |||
def setup_basic_logging(level=logging.DEBUG, formatter=None): | |||
formatter = formatter or logging.Formatter(DEFAULT_LOG_FORMAT) | |||
root = logging.getLogger() | |||
for handler in root.handlers: |
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.
Good drop, I think this was originally intended to handle re-entrant calls to setup_basic_logging where stderr stream was already setup to avoid duplication of logs to stderr. I'll double check that this is no longer an issue due to how you've changed logging call-sites in your previous logging refactors.
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 looks like it'll mean that if we get multiple calls to setup_basic_logging(<log_level>)
then we'll have duplicated logs to stderr for each LOG.root.handler managinghandler. In practice though, the CLI commands we are only calling this once in any case during handling of CLI arguments, so adding the streamhandler for stderr at a given log level will properly configure the default log-level here and I don't think we really need to solve issues with this function not being idempotent.
I think it'd be good to have a test that actually verifies that logs go to the cli when using this function. We apparently didn't have one before. |
Manual testing shows that yes CLI logging is indeed functioning, but I am still unable to get the log message to show up in either stdout or stderr in unit tests via So yeah as mentioned above, getting unit tests implemented to ensure that logs go to the cli would be useful for catching regressions in the future, but also since I am unable to get my unit tests to see logs appearing in the cli. |
Commenting out the |
8d4631c
to
f6d0ea1
Compare
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.
@holmanb great on this, the end result is much cleaner here. And ensuring we setup logging in main instead of down in subcommands also allows is to avoid potential duplication of log StreamHandler setup in subcommands.
One thing I'd suggest prior to merging is squash merging away that first commit as it adds the log_to_stderr
that you eventually drop in the last commit. in favor of a better setup in cloudinit.cmd.main.
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.
Leaving in approved
under expectation that you will do something with the commits/squashes to better represent the dropped addLogHandlerCLI from the first commit and the the final feat
commit to represent where that setup_basic_logging is now located.
Agreed, I should have mentioned that I left those commits separate in case there was objection to the optional ones that aren't needed for 23.4. I'll squash away the first refactor commit since that is redundant with removing the call entirely and shifting logic into main.py. |
Previously two subcommands used different format than the rest of them. Unify behavior and code.
Add a test for this behavior.
…ical#4617) Assertions about the host's kernel in a container are useless anyways.
f6d0ea1
to
9f3c41d
Compare
Previously two subcommands used different format than the rest of them. Unify behavior and code.
Additional Context
Issue reported by @a-dubs. Please test it if you don't mind. Rebasing your test branch on this one should work, I think.
Test Steps
Tested using this minimal test case:
Without this branch, no log is emitted. With this branch, the log appears on stderr,
Merge type