def testLimitedError(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) self.assertRaises(SystemExit, self.tester.error, "error") assert self.category == 'testlog' assert self.level == log.ERROR assert self.message == 'error'
def testFormatStrings(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) self.tester.info("%d %s", 42, 'the answer') assert self.category == 'testlog' assert self.level == log.INFO assert self.message == '42 the answer'
def testLimitInvisible(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) # log 2 we shouldn't get self.tester.log("not visible") assert not self.category assert not self.level assert not self.message self.tester.debug("not visible") assert not self.category assert not self.level assert not self.message
def testLimitedVisible(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) # log 3 we should get self.tester.info("visible") assert self.category == 'testlog' assert self.level == log.INFO assert self.message == 'visible' self.tester.warning("also visible") assert self.category == 'testlog' assert self.level == log.WARN assert self.message == 'also visible'
def testLogHandlerLimitedLevels(self): log.setDebug("testlog:3") log.addLimitedLogHandler(self.handler) # now try debug and log again too log.setDebug("testlog:5") self.tester.debug("debug") assert self.category == 'testlog' assert self.level == log.DEBUG assert self.message == 'debug' self.tester.log("log") assert self.category == 'testlog' assert self.level == log.LOG assert self.message == 'log'
def testAdaptStandardLogging(self): # create a standard logger logger = logging.getLogger('standard.logger') # set the debug level for the "test" category log.setDebug("test:3") log.addLimitedLogHandler(self.handler) logger.warning('invisible') # should not get anything, because the std module has not been adapted assert not self.category assert not self.level assert not self.message log.adaptStandardLogging('standard.logger', 'test', 'test_log') self.assertEquals(len(logger.handlers), 1) # trying to adapt it again should be a noop log.adaptStandardLogging('standard.logger', 'test', 'test_log') self.assertEquals(len(logger.handlers), 1) logger.info('invisible') # should not get anything, because INFO translates to Flu debug 4 assert not self.category assert not self.level assert not self.message logger.warning('visible') # WARNING translates to INFO, see log.stdLevelToFluLevel assert self.category == 'test', self.category assert self.level == log.INFO assert self.message == 'visible' self.message = self.level = self.category = None # lower the debug level log.setDebug("test:2") logger.warning('visible') # should not get anything now assert not self.category assert not self.level assert not self.message