def test_logger_adapter(): log = MockLog() logger = FormatAdapter(log) logger._repeat_log() # clear the log logger.debug("Debug {}", "debug") assert log.last_level is None logger.info("Info {}", "info") assert log.last_level == logging.INFO assert str(log.last_msg) == "Info info" logger.info("Test %s", "test") assert str(log.last_msg) == "Test %s" logger.warning("boo") assert str(log.last_msg) == "boo" assert log.last_level == logging.WARN logger.error("foo") assert str(log.last_msg) == "foo" assert log.last_level == logging.ERROR logger.critical("bar") assert str(log.last_msg) == "bar" assert log.last_level == logging.CRITICAL logger.set_kill_level(logging.CRITICAL) try: logger.critical("This is too high") assert False except LogLevelTooHighException: pass logger.set_kill_level() logger.critical("Should be ok now") assert len(logger._repeat_log()) == 4
def test_logger_exception(): log = MockLog() logger = FormatAdapter(log) logger._repeat_log() # clear the log class Exn(Exception): pass try: raise Exn("hi") except Exn as ex: e = ex logger.exception("ho") assert str(e) == "hi" assert str(log.last_msg) == "ho" assert "exc_info" in log.last_kwargs assert log.last_level == logging.ERROR assert len(logger._repeat_log()) == 1