def _prepare_logging(self): super(TestWithLocalLogging, self)._prepare_logging() # set up a temporary file for logging logfile = NamedTemporaryFile("w") logfile.close() self.logfile_name = logfile.name logger.register_local_log(logfile.name)
def test_register_local_log_keeps_level(self): logger.set_level(logger.ERROR) self.assertEqual(logger._level, logger.ERROR) logfile = NamedTemporaryFile("w") logfile.close() logfile_name = logfile.name logger.register_local_log(logfile_name) self.assertEqual(logger._level, logger.ERROR)
def test_basic_logging_log(self): sys.stdout = StringIO() self._collector = Collector() sh = StreamHandler(sys.stdout) sh.setFormatter(defaultFormatter) shinken_logger.handlers = [] shinken_logger.addHandler(sh) shinken_logger.load_obj(self._collector) logfile = NamedTemporaryFile("w", delete=False) logfile.close() self.logfile_name = logfile.name shinken_logger.register_local_log(logfile.name) shinken_logger.setLevel(DEBUG) self.generic_tst(lambda x: naglog_result('info', x), 'Some log-message', [1, 1, 1], ['', r'^\[\d+\] Some log-message$', r'^\[\d+\] Some log-message$'])
def test_basic_logging_log(self): sys.stdout = StringIO() self._collector = Collector() sh = StreamHandler(sys.stdout) sh.setFormatter(defaultFormatter) shinken_logger.handlers = [] shinken_logger.addHandler(sh) shinken_logger.load_obj(self._collector) logfile = NamedTemporaryFile("w", delete=False) logfile.close() self.logfile_name = logfile.name shinken_logger.register_local_log(logfile.name) shinken_logger.setLevel(DEBUG) self.generic_tst( lambda x: naglog_result('info', x), 'Some log-message', [1, 1, 1], ['', r'^\[\d+\] Some log-message$', r'^\[\d+\] Some log-message$'])
def test_none_logrotation(self): self._prepare_logging() shinken_logger.register_local_log(self.logfile_name, purge_buffer=False, log_rotation_method='n') self.assertIsInstance(shinken_logger.handlers[-1], logging.FileHandler)
def test_weekly_logrotation(self): self._prepare_logging() shinken_logger.register_local_log(self.logfile_name, purge_buffer=False, log_rotation_method='w') self.assertIsInstance(shinken_logger.handlers[-1], logging.handlers.TimedRotatingFileHandler) self.assertEqual(shinken_logger.handlers[-1].when, 'W5')