Skip to content

Commit

Permalink
Merge pull request #1279 from dandi/gh-1258
Browse files Browse the repository at this point in the history
Suppress log messages when downloading with pyout, even if no logger has been configured
  • Loading branch information
yarikoptic committed Apr 17, 2023
2 parents fea639a + 6c67784 commit bbae54e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions dandi/support/pyout.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,16 @@ class LogSafeTabular(pyout.Tabular):
def __enter__(self):
super().__enter__()
root = logging.getLogger()
for h in root.handlers:
# Use `type()` instead of `isinstance()` because FileHandler is a
# subclass of StreamHandler, and we don't want to disable it:
if type(h) is logging.StreamHandler:
h.addFilter(exclude_all)
if root.handlers:
for h in root.handlers:
# Use `type()` instead of `isinstance()` because FileHandler is
# a subclass of StreamHandler, and we don't want to disable it:
if type(h) is logging.StreamHandler:
h.addFilter(exclude_all)
self.__added_handler = None
else:
self.__added_handler = logging.NullHandler()
root.addHandler(self.__added_handler)
return self

def __exit__(self, exc_type, exc_value, tb):
Expand All @@ -229,3 +234,6 @@ def __exit__(self, exc_type, exc_value, tb):
# a subclass of StreamHandler, and we don't want to disable it:
if type(h) is logging.StreamHandler:
h.removeFilter(exclude_all)
if self.__added_handler is not None:
root.removeHandler(self.__added_handler)
self.__added_handler = None

0 comments on commit bbae54e

Please sign in to comment.