Exemplo n.º 1
0
class LoggingHttpController(HttpController):

    MAX_LOG_BUFFER_SIZE = 50
    
    def __init__(self, flask, logger, logging_dto_converter):
        super().__init__(flask)
        self._logger = logger
        self._logging_dto_converter = logging_dto_converter
        self._init_url_rules(flask)
        self._init_logger(logger)

    def _init_url_rules(self, flask):
        flask.add_url_rule('/logging/retrieve-logs', view_func = self.retrieve_logs, methods=['GET',])
        flask.add_url_rule('/logging/enable-blob-data-saving', view_func = self.enable_blob_data_saving, methods=['POST',])
        flask.add_url_rule('/logging/disable-blob-data-saving', view_func = self.disable_blob_data_saving, methods=['POST',])
        flask.add_url_rule('/logging/set-logging-level', view_func = self.set_logging_level, methods=['POST',])
        flask.add_url_rule('/logging/enable-logging', view_func = self.enable_logging, methods=['POST',])
        flask.add_url_rule('/logging/disable-logging', view_func = self.disable_logging, methods=['POST',])

    def _init_logger(self, logger):
        self._buffered_log_subscriber = InMemoryBufferedLogSubscriber(self.MAX_LOG_BUFFER_SIZE)
        logger.subscribe(self._buffered_log_subscriber)

    def retrieve_logs(self):
        log_entries = self._buffered_log_subscriber.flush()
        logging_data = self._logging_dto_converter.convert(log_entries)
        return Response(response = logging_data, status = self.HTTP_STATUS_OK, mimetype = self.JSON_MIME_TYPE)

    def enable_blob_data_saving(self):
        self._logger.save_blob_data = True
        return Response(status = self.HTTP_STATUS_OK)

    def disable_blob_data_saving(self):
        self._logger.save_blob_data = False
        return Response(status = self.HTTP_STATUS_OK)

    def enable_logging(self):
        self._buffered_log_subscriber.enabled = True
        return Response(status = self.HTTP_STATUS_OK)

    def disable_logging(self):
        self._buffered_log_subscriber.enabled = False
        return Response(status = self.HTTP_STATUS_OK)

    def set_logging_level(self):
        log_entry_type = LogEntryType(int(request.args.get('level')))
        self._logger.logging_level = log_entry_type
        return Response(status = self.HTTP_STATUS_OK)
Exemplo n.º 2
0
 def _init_logger(self, logger):
     self._buffered_log_subscriber = InMemoryBufferedLogSubscriber(self.MAX_LOG_BUFFER_SIZE)
     logger.subscribe(self._buffered_log_subscriber)