-
-
Notifications
You must be signed in to change notification settings - Fork 685
fix(logger): do not output WARN level logs for non-root modules #3760
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,7 @@ def _is_repo_debug_enabled(mrctx): | |||||||||||||
| """ | ||||||||||||||
| return mrctx.getenv(REPO_DEBUG_ENV_VAR) == "1" | ||||||||||||||
|
|
||||||||||||||
| def _logger(mrctx = None, name = None, verbosity_level = None, printer = None): | ||||||||||||||
| def _logger(mrctx = None, name = None, verbosity_level = None, printer = None, mod = None): | ||||||||||||||
| """Creates a logger instance for printing messages. | ||||||||||||||
|
|
||||||||||||||
| Args: | ||||||||||||||
|
|
@@ -42,6 +42,7 @@ def _logger(mrctx = None, name = None, verbosity_level = None, printer = None): | |||||||||||||
| taken from `mrctx`. | ||||||||||||||
| printer: a function to use for printing. Defaults to `print` or `fail` depending | ||||||||||||||
| on the logging method. | ||||||||||||||
| mod: {type}`module_ctx.module`. The module for which the logger is created. | ||||||||||||||
|
|
||||||||||||||
| Returns: | ||||||||||||||
| A struct with attributes logging: trace, debug, info, warn, fail. | ||||||||||||||
|
|
@@ -50,14 +51,22 @@ def _logger(mrctx = None, name = None, verbosity_level = None, printer = None): | |||||||||||||
| the logger injected into the function work as expected by terminating | ||||||||||||||
| on the given line. | ||||||||||||||
| """ | ||||||||||||||
| default_verbosity_level = "WARN" | ||||||||||||||
| if mod: | ||||||||||||||
| if name: | ||||||||||||||
| name = "{}:{}".format(mod.name, name) | ||||||||||||||
| else: | ||||||||||||||
| name = mod.name | ||||||||||||||
|
|
||||||||||||||
| if not mod.is_root: | ||||||||||||||
| default_verbosity_level = "ERROR" # the warnings are non actionable anyway, but we should keep them. | ||||||||||||||
|
|
||||||||||||||
| if verbosity_level == None: | ||||||||||||||
| if _is_repo_debug_enabled(mrctx): | ||||||||||||||
| verbosity_level = "DEBUG" | ||||||||||||||
| else: | ||||||||||||||
| verbosity_level = "WARN" | ||||||||||||||
| default_verbosity_level = "DEBUG" | ||||||||||||||
|
|
||||||||||||||
| env_var_verbosity = mrctx.getenv(REPO_VERBOSITY_ENV_VAR) | ||||||||||||||
| verbosity_level = env_var_verbosity or verbosity_level | ||||||||||||||
| verbosity_level = env_var_verbosity or default_verbosity_level | ||||||||||||||
|
|
||||||||||||||
| verbosity = { | ||||||||||||||
| "DEBUG": 2, | ||||||||||||||
|
Comment on lines
71
to
72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To fix this,
Suggested change
|
||||||||||||||
|
|
||||||||||||||
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 logger is created without passing the
modargument, which means it will default toWARNverbosity even when the extension is being used in a non-root module context. To be consistent with the goal of reducing log spam for non-root modules, this logger should also respect the root vs. non-root status.Since
module_ctx.modules[0]is guaranteed to be the root module if it uses the extension (and a non-root module otherwise), passing it as themodargument will correctly set the default verbosity for the global extension processing. Also, there is a minor typo in the comment (missing space).