示例#1
0
def _configure_logging(**kwargs):
    root_logger = logging.root
    global _logging_configured, _debug, silence_debug_loggers, _json_logs
    if _logging_configured:
        root_logger.info("Logging was already configured in this interpreter process. The currently "
                         "registered handlers, formatters, filters and log levels will be left as is.")
    else:
        root_logger.setLevel(logging.WARNING)
        if len(root_logger.handlers) == 0:
            logging.basicConfig(**kwargs)
        else:
            # If this happens, the process can likely proceed but the underlying issue needs to be investigated. Some
            # module isn't playing nicely and configured logging before we had a chance to do so. The backtrace
            # included in the log message may look scary but it should aid in finding the culprit.
            root_logger.warning("It appears that logging was already configured in this interpreter process. "
                                "Currently registered handlers, formatters and filters will be left as is.",
                                stack_info=True)
        if _json_logs:
            for handler in root_logger.handlers:
                formatter = FUSJsonFormatter(LOG_FORMAT)
                handler.setFormatter(formatter)
        if Config.log_level() == 0:
            _debug = False
            root_logger.setLevel(logging.WARN)
        elif Config.log_level() == 1:
            root_logger.setLevel(logging.INFO)
        elif Config.log_level() > 1:
            root_logger.setLevel(logging.DEBUG)
            for logger_name in silence_debug_loggers:
                logging.getLogger(logger_name).setLevel(logging.INFO)
        _logging_configured = True
示例#2
0
    def create_connexion_app(self):
        app = FlaskApp('fusillade')
        # The Flask/Connection app's logger has its own multi-line formatter and configuration. Rather than suppressing
        # it we let it do its thing, give it a special name and only enable it if Fusillade_DEBUG > 1.
        # Most of the Fusillade web app's logging is done through the FusilladeChaliceApp.app logger not the Flask
        # app's logger.
        app.app.logger_name = 'fus.api'
        debug = Config.log_level() > 1
        app.app.debug = debug
        app.app.logger.info('Flask debug is %s.',
                            'enabled' if debug else 'disabled')

        resolver = RestyResolver("fusillade.api",
                                 collection_endpoint_name="list")
        self.connexion_apis.append(
            app.add_api(self.swagger_spec_path,
                        resolver=resolver,
                        validate_responses=True,
                        arguments=os.environ,
                        options={"swagger_path": self.swagger_spec_path}))
        self.connexion_apis.append(
            app.add_api(self.swagger_internal_spec_path,
                        validate_responses=True))
        return app