MCPcopy
hub / github.com/celery/celery / wrap_logger

Function wrap_logger

t/unit/conftest.py:681–697  ·  view source on GitHub ↗

Wrap :class:`logging.Logger` with a StringIO() handler. yields a StringIO handle. Example:: >>> with conftest.wrap_logger(logger, loglevel=logging.DEBUG) as sio: ... ... ... sio.getvalue()

(logger, loglevel=logging.ERROR)

Source from the content-addressed store, hash-verified

679
680@contextmanager
681def wrap_logger(logger, loglevel=logging.ERROR):
682 """Wrap :class:`logging.Logger` with a StringIO() handler.
683 yields a StringIO handle.
684 Example::
685 >>> with conftest.wrap_logger(logger, loglevel=logging.DEBUG) as sio:
686 ... ...
687 ... sio.getvalue()
688 """
689 old_handlers = get_logger_handlers(logger)
690 sio = WhateverIO()
691 siohandler = logging.StreamHandler(sio)
692 logger.handlers = [siohandler]
693
694 try:
695 yield sio
696 finally:
697 logger.handlers = old_handlers
698
699
700@contextmanager

Callers

nothing calls this directly

Calls 2

get_logger_handlersFunction · 0.85
WhateverIOClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…