human
Solve the following python programming problem given the following code:
@contextmanager
def patch_logger(logger_name, log_level, log_kwargs=False):
assistant
#Here is the Python code you requested.

    """Context manager that takes a named logger and the logging level
    and provides a simple mock-like list of messages received
    """
    calls = []
    def replacement(msg, *args, **kwargs):
        call = (msg % args)
        calls.append(((call, kwargs) if log_kwargs else call))
    logger = logging.getLogger(logger_name)
    orig = getattr(logger, log_level)
    setattr(logger, log_level, replacement)
    try:
        (yield calls)
    finally:
        setattr(logger, log_level, orig)