MCPcopy Create free account
hub / github.com/celery/celery / wrap_logger

Function wrap_logger

t/unit/conftest.py:702–718  ·  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

700
701@contextmanager
702def wrap_logger(logger, loglevel=logging.ERROR):
703 """Wrap :class:`logging.Logger` with a StringIO() handler.
704 yields a StringIO handle.
705 Example::
706 >>> with conftest.wrap_logger(logger, loglevel=logging.DEBUG) as sio:
707 ... ...
708 ... sio.getvalue()
709 """
710 old_handlers = get_logger_handlers(logger)
711 sio = WhateverIO()
712 siohandler = logging.StreamHandler(sio)
713 logger.handlers = [siohandler]
714
715 try:
716 yield sio
717 finally:
718 logger.handlers = old_handlers
719
720
721@contextmanager

Callers

nothing calls this directly

Calls 2

get_logger_handlersFunction · 0.85
WhateverIOClass · 0.70

Tested by

no test coverage detected