def initialize_logging(): kafkalogger = logging.getLogger("kafka") kafkalogger.addHandler(logging.StreamHandler(sys.stdout)) kafkalogger.setLevel(os.getenv("LOG_LEVEL", "INFO")) if any("KUBERNETES" in k for k in os.environ): handler = logging.StreamHandler(sys.stdout) handler.setFormatter(LogstashFormatterV1()) logging.root.setLevel(os.getenv("LOG_LEVEL", "INFO")) logging.root.addHandler(handler) else: logging.basicConfig( level="INFO", format="%(threadName)s %(levelname)s %(name)s - %(message)s" ) logger = logging.getLogger(app_config.get_app_name()) if config.aws_access_key_id and config.aws_secret_access_key: logger.warn("configuring cloudwatch logging") config_cloudwatch(logger) logger.warn("cloudwatch logging ENABLED") else: logger.warn("cloudwatch logging DISABLED") return logger
def create_connexion_app(): openapi_args = { "path_prefix": kerlescan_config.path_prefix, "app_name": app_config.get_app_name(), } connexion_app = connexion.App(__name__, specification_dir="openapi/", arguments=openapi_args) connexion_app.add_api("api.spec.yaml", strict_validation=True, validate_responses=True) connexion_app.add_api("mgmt_api.spec.yaml", strict_validation=True) flask_app = connexion_app.app # set up logging ASAP setup_audit_logging(logging.Logger) gunicorn_logger = logging.getLogger("gunicorn.error") flask_app.logger.handlers = gunicorn_logger.handlers flask_app.logger.setLevel(gunicorn_logger.level) setup_cw_logging(flask_app.logger) register_hsts_response(flask_app) # set up DB engine_options = { "pool_pre_ping": True, "pool_recycle": 300, "pool_size": config.db_pool_size, "pool_timeout": config.db_pool_timeout, } flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False flask_app.config["SQLALCHEMY_DATABASE_URI"] = config.db_uri flask_app.config["SQLALCHEMY_ENGINE_OPTIONS"] = engine_options flask_app.config["SQLALCHEMY_ECHO"] = False if config.log_sql_statements: flask_app.config["SQLALCHEMY_ECHO"] = True db.init_app(flask_app) flask_app.register_blueprint(v1.section) flask_app.register_error_handler(HTTPError, handle_http_error) return connexion_app