MCPcopy
hub / github.com/mne-tools/mne-python / catch_logging

Class catch_logging

mne/utils/_logging.py:311–338  ·  view source on GitHub ↗

Store logging. This will remove all other logging handlers, and return the handler to stdout when complete.

Source from the content-addressed store, hash-verified

309
310
311class catch_logging:
312 """Store logging.
313
314 This will remove all other logging handlers, and return the handler to
315 stdout when complete.
316 """
317
318 def __init__(self, verbose=None):
319 self.verbose = verbose
320
321 def __enter__(self): # noqa: D105
322 if self.verbose is not None:
323 self._ctx = use_log_level(self.verbose)
324 else:
325 self._ctx = contextlib.nullcontext()
326 self._data = ClosingStringIO()
327 self._lh = logging.StreamHandler(self._data)
328 self._lh.setFormatter(logging.Formatter("%(message)s"))
329 self._lh._mne_file_like = True # monkey patch for warn() use
330 _remove_close_handlers(logger)
331 logger.addHandler(self._lh)
332 self._ctx.__enter__()
333 return self._data
334
335 def __exit__(self, *args): # noqa: D105
336 self._ctx.__exit__(*args)
337 logger.removeHandler(self._lh)
338 set_log_file(None)
339
340
341@contextlib.contextmanager

Callers 15

test_progressbarFunction · 0.90
test_run_subprocessFunction · 0.90
test_check_info_invFunction · 0.90
test_logging_optionsFunction · 0.90
test_verbose_methodFunction · 0.90
test_verbose_strictnessFunction · 0.90
test_fine_cal_systemsFunction · 0.90
test_other_systemsFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_progressbarFunction · 0.72
test_run_subprocessFunction · 0.72
test_check_info_invFunction · 0.72
test_logging_optionsFunction · 0.72
test_verbose_methodFunction · 0.72
test_verbose_strictnessFunction · 0.72
test_fine_cal_systemsFunction · 0.72
test_other_systemsFunction · 0.72