Remove usage of get_logger_obj

This commit is contained in:
Thomas Hisch 2017-09-26 23:05:42 +02:00
parent 0ec72d0745
commit 1f3ab118fa
1 changed files with 2 additions and 12 deletions

View File

@ -78,20 +78,10 @@ def pytest_addoption(parser):
help='log date format as used by the logging module.')
def get_logger_obj(logger=None):
"""Get a logger object that can be specified by its name, or passed as is.
Defaults to the root logger.
"""
if logger is None or isinstance(logger, py.builtin._basestring):
logger = logging.getLogger(logger)
return logger
@contextmanager
def logging_using_handler(handler, logger=None):
"""Context manager that safely registers a given handler."""
logger = get_logger_obj(logger)
logger = logger or logging.getLogger(logger)
if handler in logger.handlers: # reentrancy
# Adding the same handler twice would confuse logging system.
@ -109,7 +99,7 @@ def logging_using_handler(handler, logger=None):
def catching_logs(handler, formatter=None,
level=logging.NOTSET, logger=None):
"""Context manager that prepares the whole logging machinery properly."""
logger = get_logger_obj(logger)
logger = logger or logging.getLogger(logger)
if formatter is not None:
handler.setFormatter(formatter)