Skip to content

Commit

Permalink
avoid duplicate logging by preventing propagation from the conda_buil…
Browse files Browse the repository at this point in the history
…d logger to the root logger (#4903)

* avoid duplicate logging by preventing propagation from the conda_build logger to the root logger
* print level for warnings and errors
* fix tests/test_utils.py::test_logger_filtering
  • Loading branch information
jaimergp committed Jul 17, 2023
1 parent 19fb62c commit b8c4b53
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion conda_build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,7 @@ def filter(self, record):
dedupe_filter = DuplicateFilter()
info_debug_stdout_filter = LessThanFilter(logging.WARNING)
warning_error_stderr_filter = GreaterThanFilter(logging.INFO)
level_formatter = logging.Formatter("%(levelname)s: %(message)s")

# set filelock's logger to only show warnings by default
logging.getLogger("filelock").setLevel(logging.WARN)
Expand Down Expand Up @@ -1746,11 +1747,17 @@ def get_logger(name, level=logging.INFO, dedupe=True, add_stdout_stderr_handlers
log.addFilter(dedupe_filter)

# these are defaults. They can be overridden by configuring a log config yaml file.
if not log.handlers and add_stdout_stderr_handlers:
top_pkg = name.split(".")[0]
if top_pkg == "conda_build":
# we don't want propagation in CLI, but we do want it in tests
# this is a pytest limitation: https://github.com/pytest-dev/pytest/issues/3697
logging.getLogger(top_pkg).propagate = "PYTEST_CURRENT_TEST" in os.environ
if add_stdout_stderr_handlers and not log.handlers:
stdout_handler = logging.StreamHandler(sys.stdout)
stderr_handler = logging.StreamHandler(sys.stderr)
stdout_handler.addFilter(info_debug_stdout_filter)
stderr_handler.addFilter(warning_error_stderr_filter)
stderr_handler.setFormatter(level_formatter)
stdout_handler.setLevel(level)
stderr_handler.setLevel(level)
log.addHandler(stdout_handler)
Expand Down
19 changes: 19 additions & 0 deletions news/4903-duplicate-logging
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Avoid duplicate logging by not propagating the top-level conda-build logger. (#4903)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit b8c4b53

Please sign in to comment.