def test_get_logs_by_level(self): Utils.prepare_test(connect_logger=True) TestLogger.load_logs() start_date = datetime.datetime.now().timestamp() - 10 end_date = datetime.datetime.now().timestamp() + 10 logs = Logger.get_logs(Logger.DEBUG, None, start_date, end_date) self.assertEqual(4, len(logs)) logs = Logger.get_logs(Logger.WARNING, None, start_date, end_date) self.assertEqual(2, len(logs))
def test_get_logs_by_date(self): Utils.prepare_test(connect_logger=True) TestLogger.load_logs() start_date = TestLogger.VERY_FAR_IN_TIME - 10 end_date = TestLogger.VERY_FAR_IN_TIME + 10 logs = Logger.get_logs(Logger.DEBUG, None, start_date, end_date) self.assertEqual(1, len(logs))
def test_get_logs_by_category(self): Utils.prepare_test(connect_logger=True) TestLogger.load_logs() start_date = datetime.datetime.now().timestamp() - 10 end_date = datetime.datetime.now().timestamp() + 10 logs = Logger.get_logs(Logger.DEBUG, "CATEGORY", start_date, end_date) self.assertEqual(2, len(logs))
def log(self, start_date: str, end_date: str, level: str, category: str = None): """ POST /admin/log """ if level not in Logger.HUMAN_MESSAGES: self.raise_exc(BadRequest, "INVALID_PARAMETER", "The level provided is invalid") level = Logger.HUMAN_MESSAGES.index(level) try: start_date = dateutil.parser.parse(start_date).timestamp() end_date = dateutil.parser.parse(end_date).timestamp() except ValueError as e: BaseHandler.raise_exc(BadRequest, "INVALID_PARAMETER", str(e)) return BaseHandler.format_dates( {"items": Logger.get_logs(level, category, start_date, end_date)})