def set_level(self, level, logger=None):
logger_name = logger<EOL>logger = logging.getLogger(logger_name)<EOL>self._initial_log_levels.setdefault(logger_name, logger.level)<EOL>logger.setLevel(level)<EOL>
Sets the level for capturing of logs. The level will be restored to its previous value at the end of
        the test.

        :param int level: the logger to level.
        :param str logger: the logger to update the level. If not given, the root logger level is updated.

        .. versionchanged:: 3.4
            The levels of the loggers changed by this function will be restored to their initial values at the
            end of the test.