def init_sentry(): """ init sentry :return: """ from raven import Client from raven.handlers.logging import SentryHandler from raven.conf import setup_logging from complexconfig.configcontainer import configcontainer config = configcontainer.get_config("sniffer") enable = config.get_boolean("sniffer.sentry.enable", False) if not enable: return sentry_level = config.get_string("sniffer.sentry.min_level", "error") sentry_server_name = config.get_string("sniffer.sentry.server_name", "") sentry_dsn = config.get_string("sniffer.sentry.dsn", "") if not sentry_dsn or not sentry_server_name: return print_with_time("sentry is enabled with dsn: {}, server_name: {}, level: {}".format(sentry_dsn, sentry_server_name, sentry_level)) client = Client(sentry_dsn, name=sentry_server_name) handler = SentryHandler(client) if sentry_level.lower() == 'debug': handler.level = logging.DEBUG elif sentry_level.lower() == 'info': handler.level = logging.INFO else: handler.level = logging.ERROR setup_logging(handler)
def init_logging(app): location_log_config = app.config['LOGGING_CONFIG_LOCATION'] if os.path.isfile(location_log_config): logging.config.fileConfig(location_log_config, disable_existing_loggers=True) logger.info('Loaded logging configuration file "%s"', location_log_config) else: logger.warning('Error loading configuration file "%s"', location_log_config) if app.config['SENTRY_DSN']: # This could not be done in the default .ini because the # handler has to be passed to `raven.setup_logging`. # the following adds itself to app.extensions['sentry'] sentry = Sentry() sentry.init_app(app, dsn=app.config['SENTRY_DSN']) handler = SentryHandler(app.extensions['sentry'].client) handler.level = logging.NOTSET setup_logging(handler) logger.debug("Sentry DSN: {}".format(app.config['SENTRY_DSN'])) else: logger.debug("No sentry DSN specified")
def SentryHandler(dns=None, level=logging.WARNING): from raven.handlers.logging import SentryHandler dns = dns or os.environ.get("SENTRY") sentry_handler = SentryHandler(dns) sentry_handler.level = level return sentry_handler
rotate_file_handler.setFormatter(fmt) logging.root.addHandler(rotate_file_handler) level = logging.DEBUG if settings.DEBUG else logging.WARN if level is not None: logging.root.setLevel(level) # 判断是否开启sentry if settings.Sentry_Enable: from raven import Client from raven.handlers.logging import SentryHandler from raven.conf import setup_logging client = Client(settings.Sentry_Dsn_Web, name=settings.Server_Name) handler = SentryHandler(client) if settings.Sentry_Min_Level.lower() == 'debug': handler.level = logging.DEBUG elif settings.Sentry_Min_Level.lower() == 'info': handler.level = logging.INFO else: handler.level = logging.ERROR setup_logging(handler) logger = logging.getLogger('nebula.cli.admin') # metrics 初始化配置 metrics_dict = { "app": "nebula_web", "redis": { "type": "redis", "host": settings.Redis_Host, "port": settings.Redis_Port