Example #1
0
def _get_log_handler(handler_name="mwcp_server"):
    """
    Get the handler for the parser running.

    Attempts to get 'mwcp_server' handler from the root logger, and create
    a clean copy, keeping any formatters and level settings.

    If the handler does not exist, create a default handler.
    """
    handler = _get_existing_handler(handler_name)
    if handler:
        if isinstance(handler, logutil.ListHandler):
            new_handler = copy(handler)
            new_handler.clear()
            return new_handler
        f.current_app.logger.warning(
            "Root handler '{}' is not a ListHandler.".format(handler_name)
        )

    f.current_app.logger.info(
        "No 'mwcp_server' handler defined on root logger. Using default."
    )
    list_handler = logutil.ListHandler()
    list_handler.setFormatter(
        logging.Formatter("[%(level_char)s] (%(name)s): %(message)s")
    )
    list_handler.addFilter(logutil.LevelCharFilter())

    return list_handler
Example #2
0
    def __reset(self):
        """
        Reset all the data in the reporter object that is set during the run_parser function

        Goal is to make the reporter safe to use for multiple run_parser instances
        """
        self._managed_tempdir = None
        self.input_file = None

        self.metadata = {}
        self.errors = []

        # To keep backwards compatibility, setup log handler to add errors and debug messages to reporter.
        # TODO: Remove this when the Reporter object should no longer be responsible for logging.
        log_handler = ReporterLogHandler(self)
        logging.root.addHandler(log_handler)
        # Setup a simple format that doesn't contain any runtime variables.
        log_handler.addFilter(logutil.LevelCharFilter())
        log_handler.setFormatter(logging.Formatter("[%(level_char)s] %(message)s"))
        self._log_handler = log_handler