예제 #1
0
파일: __init__.py 프로젝트: ox-it/moxie
def create_app():
    app = Moxie(__name__)
    configurator = Configurator(app)
    cfg_path = path.join(app.root_path, 'default_settings.yaml')
    configurator.from_yaml(cfg_path)
    configurator.from_envvar('MOXIE_SETTINGS', silent=True)

    # logging configuration for Raven/Sentry
    if raven_available and 'SENTRY_DSN' in app.config:
        sentry = Sentry(dsn=app.config['SENTRY_DSN'])
        # capture uncaught exceptions within Flask
        sentry.init_app(app)
        handler = SentryHandler(app.config['SENTRY_DSN'],
                                level=logging.getLevelName(
                                    app.config.get('SENTRY_LEVEL', 'WARNING')))
        setup_logging(handler)

    statsd.init_app(app)
    cache.init_app(app)
    db.init_app(app)

    # Static URL Route for API Health checks
    app.add_url_rule('/_health', view_func=check_services)
    app.add_url_rule('/', view_func=RootView.as_view('root'))
    return app
예제 #2
0
    def init_app(self, app, dsn=None, logging=None, level=None, wrap_wsgi=None, register_signal=None):
        if dsn is not None:
            self.dsn = dsn

        if level is not None:
            self.level = level

        if wrap_wsgi is not None:
            self.wrap_wsgi = wrap_wsgi

        if register_signal is not None:
            self.register_signal = register_signal

        if logging is not None:
            self.logging = logging

        if not self.client:
            self.client = make_client(self.client_cls, app, self.dsn)

        if self.logging:
            setup_logging(SentryHandler(self.client, level=self.level))

        if self.wrap_wsgi:
            app.wsgi_app = SentryMiddleware(app.wsgi_app, self.client)

        app.before_request(self.before_request)

        if self.register_signal:
            got_request_exception.connect(self.handle_exception, sender=app)
            request_finished.connect(self.add_sentry_id_header, sender=app)

        if not hasattr(app, "extensions"):
            app.extensions = {}
        app.extensions["sentry"] = self
예제 #3
0
def start_manager():
    if config.SENTRY_DSN:
        handler = SentryHandler(config.SENTRY_DSN)
        setup_logging(handler)

    r = redis.StrictRedis(
        host=config.REDIS_HOST,
        port=config.REDIS_PORT,
        db=config.REDIS_DB
    )
    manager = BotManager(BotificoBot)

    while True:
        result = r.lpop('queue_message')
        if result:
            m = json.loads(result)
            if m['type'] == 'message':
                channel = m['channel']
                payload = m['payload']

                manager.send_message(
                    Network(
                        host=channel['host'],
                        port=channel['port'],
                        ssl=channel['ssl'],
                        password=channel.get('password', None)
                    ),
                    Channel(
                        channel=channel['channel'],
                        password=channel.get('channel_password', None)
                    ),
                    payload['msg']
                )

        gevent.sleep(0.1)
예제 #4
0
def initialize_raven(config):
    client_dsn = config.get('sentry_client_dsn', '').strip()
    enabled = config.get('sentry_enabled', True)
    report_user_errors = config.get('sentry_report_user_errors', False)
    include_extra_context = config.get('sentry_include_context', True)
    level = config.get('sentry_logging_level', DEFAULT_LOG_LEVEL)
    environment = config.get('sentry_environment')
    auto_log_stacks = config.get('sentry_auto_log_stacks', False)
    odoo_dir = config.get('sentry_odoo_dir')

    client = Client(
        client_dsn,
        install_sys_hook=False,
        release=get_odoo_commit(odoo_dir),
        environment=environment,
        auto_log_stacks=auto_log_stacks,
    )

    if level not in LOG_LEVEL_MAP:
        level = DEFAULT_LOG_LEVEL

    if enabled:
        handler = OdooSentryHandler(
            include_extra_context,
            client=client,
            level=LOG_LEVEL_MAP[level],
        )
        if not report_user_errors:
            handler.addFilter(UserErrorFilter())
        setup_logging(handler)

    return client
예제 #5
0
def install():
    from nexel.config.settings import Settings
    from nexel.handlers import dispatcher
    from tornado import version_info
    if version_info[0] >= 3:
        import tornado.log
        tornado.log.enable_pretty_logging()
    else:
        import tornado.options
        tornado.options.enable_pretty_logging()

    # global logging level
    if Settings()['debug']:
        logging.getLogger().setLevel(logging.DEBUG)
    else:
        logging.getLogger().setLevel(logging.INFO)

    # webapp
    import tornado.web
    web_app = tornado.web.Application(dispatcher, debug=Settings()['debug'],
                                      log_function=webapp_log)
    web_app.listen(Settings()['server_port'])

    # sentry logging
    if Settings()['sentry-api-key']:
        web_app.sentry_client = AsyncSentryClient(Settings()['sentry-api-key'])
        setup_logging(SentryHandler(Client(Settings()['sentry-api-key'])))

    return web_app
예제 #6
0
파일: manage.py 프로젝트: eea/gioland
def create_app(config={}, testing=False):
    from gioland import auth
    from gioland import parcel
    from gioland import warehouse
    from gioland import utils
    app = flask.Flask(__name__)
    app.config.update(copy.deepcopy(default_config))
    if testing:
        app.config['TESTING'] = True
    else:
        app.config.update(configuration_from_environ())
    app.config.update(config)
    warehouse.initialize_app(app)
    auth.register_on(app)
    parcel.register_on(app)
    register_monitoring_views(app)
    utils.initialize_app(app)

    sentry_dsn = app.config.get('SENTRY_DSN')
    if sentry_dsn:
        from raven.conf import setup_logging
        from raven.handlers.logging import SentryHandler
        setup_logging(SentryHandler(sentry_dsn, level=logging.WARN))

    return app
예제 #7
0
파일: __init__.py 프로젝트: N3X15/notifico
def start_manager():
    if config.SENTRY_DSN:
        handler = SentryHandler(config.SENTRY_DSN)
        setup_logging(handler)

    r = redis.StrictRedis(host=config.REDIS_HOST, port=config.REDIS_PORT, db=config.REDIS_DB)
    manager = BotManager(BotificoBot)

    while True:
        result = r.lpop("queue_message")
        if result:
            m = json.loads(result)
            if m["type"] == "message":
                channel = m["channel"]
                payload = m["payload"]

                manager.send_message(
                    Network(
                        host=channel["host"],
                        port=channel["port"],
                        ssl=channel["ssl"],
                        password=channel.get("password", None),
                    ),
                    Channel(channel=channel["channel"], password=channel.get("channel_password", None)),
                    payload["msg"],
                )

        gevent.sleep(0.1)
예제 #8
0
 def __init__(self, app, client, logging=False):
     self.app = app
     self.client = client
     self.logging = logging
     if self.logging:
         setup_logging(SentryHandler(self.client))
     self.app.sentry = self
예제 #9
0
    def load_sentry(self):
        if self.clientid == "":
            return

        self.raven = Client(self.clientid, transport=AioHttpTransport)
        self.handler = SentryHandler(self.raven)
        setup_logging(self.handler)
        log.debug("Sentry handler activated.")
예제 #10
0
파일: util.py 프로젝트: 40a/aurproxy
def setup_sentry(dsn=None):
  """Configures the Sentry logging handler.

  Args:
    dsn - DSN for the Sentry project.
  """
  handler = SentryHandler(dsn, level=logging.ERROR)
  setup_logging(handler)
예제 #11
0
    def sentry_handler(self):
        """Sentry log handler."""
        if self.sentry_client:
            from raven.conf import setup_logging
            from raven.handlers.logging import SentryHandler

            handler = SentryHandler(self.sentry_client)
            setup_logging(handler)
            return handler
예제 #12
0
파일: __init__.py 프로젝트: Polychart/raven
    def init_app(self, app):
        self.app = app
        if not self.client:
            self.client = make_client(self.client_cls, app, self.dsn)

        if self.logging:
            setup_logging(SentryHandler(self.client))

        got_request_exception.connect(self.handle_exception, sender=app, weak=False)
예제 #13
0
    def init_app(self, app, dsn=None, logging=None, level=None,
                 logging_exclusions=None, wrap_wsgi=None,
                 register_signal=None):
        if dsn is not None:
            self.dsn = dsn

        if level is not None:
            self.level = level

        if wrap_wsgi is not None:
            self.wrap_wsgi = wrap_wsgi
        elif self.wrap_wsgi is None:
            # Fix https://github.com/getsentry/raven-python/issues/412
            # the gist is that we get errors twice in debug mode if we don't do this
            if app and app.debug:
                self.wrap_wsgi = False
            else:
                self.wrap_wsgi = True

        if register_signal is not None:
            self.register_signal = register_signal

        if logging is not None:
            self.logging = logging

        if logging_exclusions is not None:
            self.logging_exclusions = logging_exclusions

        if not self.client:
            self.client = make_client(self.client_cls, app, self.dsn)

        if self.logging:
            kwargs = {}
            if self.logging_exclusions is not None:
                kwargs['exclude'] = self.logging_exclusions
            handler = SentryHandler(self.client, level=self.level)
            setup_logging(handler, **kwargs)

            if app.logger.propagate is False:
                app.logger.addHandler(handler)

            logging_configured.send(
                self, sentry_handler=SentryHandler, **kwargs)

        if self.wrap_wsgi:
            app.wsgi_app = SentryMiddleware(app.wsgi_app, self.client)

        app.before_request(self.before_request)
        request_finished.connect(self.after_request, sender=app)

        if self.register_signal:
            got_request_exception.connect(self.handle_exception, sender=app)

        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['sentry'] = self
예제 #14
0
 def _sentry_handler(sentry_key=None, obci_peer=None):
     try:
         client = OBCISentryClient(sentry_key, obci_peer=obci_peer, auto_log_stacks=True)
     except ValueError as e:
         print('logging setup: initializing sentry failed - ', e.args)
         return None
     handler = SentryHandler(client)
     handler.set_name('sentry_handler')
     setup_logging(handler)
     return handler
예제 #15
0
    def __init__(self, domain, DSN):
        from raven.handlers.logging import SentryHandler
        from raven.conf import setup_logging

        self.domain = domain
        self.dsn = DSN
        
        handler = SentryHandler(self.dsn)
        setup_logging(handler)
        self.logger = logging.getLogger('linkcheck')
예제 #16
0
파일: args.py 프로젝트: odony/gitfs
    def check_args(self, args):
        # check allow_other and allow_root
        if args.allow_other:
            args.allow_root = False
        else:
            args.allow_root = True

        # check log_level
        if args.debug:
            args.log_level = 'debug'

        # setup logging
        if args.log != "syslog":
            if args.log in ('-', '/dev/stdout'):
                handler = StreamHandler(sys.stdout)
            else:
                handler = TimedRotatingFileHandler(args.log, when="midnight")
            handler.setFormatter(
                Formatter(fmt='%(asctime)s %(threadName)s: '
                          '%(message)s',
                          datefmt='%B-%d-%Y %H:%M:%S'))
        else:
            if sys.platform == 'darwin':
                handler = SysLogHandler(address="/var/run/syslog")
            else:
                handler = SysLogHandler(address="/dev/log")
            logger_fmt = 'GitFS on {mount_point} [%(process)d]: %(threadName)s: '\
                         '%(message)s'.format(mount_point=args.mount_point)
            handler.setFormatter(Formatter(fmt=logger_fmt))

        if args.sentry_dsn != '':
            from raven.conf import setup_logging
            from raven.handlers.logging import SentryHandler

            sentry_handler = SentryHandler(args.sentry_dsn,
                                           tags={
                                               'owner': args.user,
                                               'remote': args.remote_url,
                                               'mountpoint': args.mount_point
                                           })
            sentry_handler.setLevel("ERROR")
            setup_logging(sentry_handler)
            log.addHandler(sentry_handler)

        handler.setLevel(args.log_level.upper())
        log.setLevel(args.log_level.upper())
        log.addHandler(handler)

        # set cache size
        lru_cache.maxsize = args.cache_size

        # return absolute repository's path
        args.repo_path = os.path.abspath(args.repo_path)

        return args
예제 #17
0
    def init_app(self, app, dsn=None, logging=None, level=None,
                 logging_exclusions=None, wrap_wsgi=None,
                 register_signal=None):
        if dsn is not None:
            self.dsn = dsn

        if level is not None:
            self.level = level

        if wrap_wsgi is not None:
            self.wrap_wsgi = wrap_wsgi
        elif self.wrap_wsgi is None:
            # Fix https://github.com/getsentry/raven-python/issues/412
            # the gist is that we get errors twice in debug mode if we don't do this
            if app and app.debug:
                self.wrap_wsgi = False
            else:
                self.wrap_wsgi = True

        if register_signal is not None:
            self.register_signal = register_signal

        if logging is not None:
            self.logging = logging

        if logging_exclusions is not None:
            self.logging_exclusions = logging_exclusions

        if not self.client:
            self.client = make_client(self.client_cls, app, self.dsn)

        if self.logging:
            kwargs = {}
            if self.logging_exclusions is not None:
                kwargs['exclude'] = self.logging_exclusions

            handler = SentryHandler(self.client, level=self.level)
            setup_logging(handler, **kwargs)

            logging_configured.send(
                self, sentry_handler=SentryHandler, **kwargs)

        if self.wrap_wsgi:
            app.wsgi_app = SentryMiddleware(app.wsgi_app, self.client)

        app.before_request(self.before_request)

        if self.register_signal:
            got_request_exception.connect(self.handle_exception, sender=app)
            request_finished.connect(self.after_request, sender=app)

        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['sentry'] = self
예제 #18
0
파일: manage.py 프로젝트: eea/ldaplog
def main():
    DEBUG = (os.environ.get('DEBUG') == 'on')
    configure_logging(level=logging.DEBUG if DEBUG else logging.INFO)

    SENTRY_DSN = os.environ.get('SENTRY_DSN')
    if SENTRY_DSN:
        from raven.conf import setup_logging
        from raven.handlers.logging import SentryHandler
        setup_logging(SentryHandler(SENTRY_DSN, level=logging.ERROR))

    manager.run()
예제 #19
0
    def init_app(self, app):
        self.app = app
        if not self.client:
            self.client = make_client(self.client_cls, app, self.dsn)

        if self.logging:
            setup_logging(SentryHandler(self.client))

        got_request_exception.connect(self.handle_exception,
                                      sender=app,
                                      weak=False)
예제 #20
0
def init_sentry():
    logger.debug('Initializing Sentry loghandler')
    client = LambdaClient(auto_log_stacks=True)
    loghandler = SentryHandler(client)
    loghandler.setLevel('ERROR')
    setup_logging(loghandler)

    logger.debug('Applying Sentry celery signals and logging hooks')
    register_logger_signal(client, loglevel=logging.INFO)
    register_signal(client, ignore_expected=False)
    return client
예제 #21
0
def setup_sentry(dsn):
    if SentryHandler and setup_logging:
        if dsn:
            handler = SentryHandler(dsn)
            handler.setLevel(logging.ERROR)
            setup_logging(handler)
            logger.info('log handler for Sentry was successfuly set up')
        else:
            logger.info('cannot setup handler for Sentry: missing DSN')
    else:
        logger.info(
            'cannot setup handler for Sentry: make sure raven is installed')
예제 #22
0
파일: peasoup.py 프로젝트: timeyyy/apptools
def setup_raven():
    '''we setup sentry to get all stuff from our logs'''
    pcfg = AppBuilder.get_pcfg()
    from raven.handlers.logging import SentryHandler
    from raven import Client
    from raven.conf import setup_logging
    client = Client(pcfg['raven_dsn'])
    handler = SentryHandler(client)
    # TODO VERIFY THIS -> This is the way to do it if you have a paid account, each log call is an event so this isn't going to work for free accounts...
    handler.setLevel(pcfg["raven_loglevel"])
    setup_logging(handler)
    return client
예제 #23
0
def setup(server_version):
    client = Client(
        "https://*****:*****@sentry.io/220532",
        transport=AioHttpTransport,
        release=server_version)

    handler = SentryHandler(client)
    handler.setLevel(logging.ERROR)

    setup_logging(handler)

    return client
예제 #24
0
파일: __init__.py 프로젝트: samj1912/sir
def init_raven_client(dsn):
    global _sentry
    _sentry = raven.Client(
        dsn=dsn,
        transport=raven.transport.threaded_requests.ThreadedRequestsHTTPTransport,
        ignore_exceptions={'KeyboardInterrupt'},
        logging=True,
    )
    sentry_errors_logger = logging.getLogger("sentry.errors")
    sentry_errors_logger.addHandler(logging.StreamHandler())
    handler = SentryHandler(_sentry)
    handler.setLevel(logging.ERROR)
    setup_logging(handler)
예제 #25
0
def init(dsn=None):
    """Redirect Scrapy log messages to standard Python logger"""

    observer = log.PythonLoggingObserver()
    observer.start()

    dict_config = settings.get("LOGGING")
    if dict_config is not None:
        assert isinstance(dict_config, dict)
        logging.dictConfig(dict_config)

    handler = SentryHandler(dsn)
    setup_logging(handler)
예제 #26
0
def install_sentry_logger():
    try:
        import raven
    except ImportError:
        logging.warning('Unable to find raven library. Sentry integration disabled.')
        return

    from raven.conf import setup_logging
    from raven.handlers.logging import SentryHandler

    client = raven.Client()
    handler = SentryHandler(client, level=logging.WARN)
    setup_logging(handler)
예제 #27
0
async def _startup(app: web.Application) -> None:
    dsn = os.environ["SENTRY_DSN"]
    environment = app["config"]["app"]["environment"]

    sentry_client = SentryClient(dsn=dsn,
                                 transport=AioHttpTransport,
                                 environment=environment)

    sentry_logging_handler = SentryHandler(sentry_client)
    sentry_logging_handler.setLevel(logging.ERROR)
    setup_logging(sentry_logging_handler)

    app["sentry"] = sentry_client
예제 #28
0
def _setup_logger_raven(logger_name):
    global __RAVEN_INIT
    if not __RAVEN_INIT:
        from raven import Client
        from raven.handlers.logging import SentryHandler
        client = Client("https://")
        raven_handler = SentryHandler(client)
        __RAVEN_INIT = True
        from raven.conf import setup_logging
        setup_logging(raven_handler)

    logger = logging.getLogger(logger_name)
    return logger
예제 #29
0
    def init_app(self, app):
        self.app = app
        if not self.client:
            self.client = make_client(self.client_cls, app, self.dsn)

        if self.logging:
            setup_logging(SentryHandler(self.client))

        got_request_exception.connect(self.handle_exception, sender=app)

        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['sentry'] = self
예제 #30
0
def init(dsn=None):
    """Redirect Scrapy log messages to standard Python logger"""

    observer = log.PythonLoggingObserver()
    observer.start()

    dict_config = settings.get("LOGGING")
    if dict_config is not None:
        assert isinstance(dict_config, dict)
        logging.dictConfig(dict_config)

    handler = SentryHandler(dsn)
    setup_logging(handler)
예제 #31
0
def initialize_sentry():
    client = Raven(SentrySettings.getURL())
    client.tags_context({
        'Aspect': 'Backend',
        'Language': 'Python',
        'logger': 'python'
    })

    handler = SentryHandler(client)
    handler.setLevel(logging.ERROR)
    setup_logging(handler)

    return client
예제 #32
0
    def init_app(self, app):
        self.app = app
        if not self.client:
            self.client = make_client(self.client_cls, app, self.dsn)

        if self.logging:
            setup_logging(SentryHandler(self.client))

        got_request_exception.connect(self.handle_exception, sender=app)

        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['sentry'] = self
예제 #33
0
def logger_pick(mode, sentry_url):
    """ Load the logger for the bot. """
    global logger

    if mode != "production":
        logger = DummyLogger()
        return logger

    client = Client(sentry_url)
    handler = SentryHandler(client)
    handler.setLevel(logging.DEBUG)
    setup_logging(handler)
    logger = logging.getLogger(__name__)
    return logger
예제 #34
0
def setup(dsn, level, propagate_sentry_errors=False):
    client = make_client(dsn, False)
    
    from raven.handlers.logging import SentryHandler
    global handler
    handler = SentryHandler(client)
    handler.setLevel(level)
    handler.dsn = dsn
    
    from raven.conf import setup_logging
    kwargs = {}
    if propagate_sentry_errors:
        kwargs["exclude"] = []
    setup_logging(handler, **kwargs)
예제 #35
0
 def init_app(self, app):
     dsn = app.config.get('SENTRY_DSN')
     if dsn:
         client = raven.Client(dsn)
         handler = SentryHandler(client)
         handler.setLevel(logging.ERROR)
         setup_logging(handler)
         try:
             from raven.contrib.celery import (register_signal,
                                               register_logger_signal)
             register_logger_signal(client)
             register_signal(client)
         except ImportError:
             pass
예제 #36
0
def setup():
    global done
    if done:
        return
    import os
    if os.environ.get("sentry"):
        import logging
        from raven.handlers.logging import SentryHandler
        handler = SentryHandler(os.environ.get("sentry"), level=logging.INFO)
        from raven.conf import setup_logging
        setup_logging(handler)
        root = logging.getLogger()
        root.setLevel(logging.INFO)
    done = True
예제 #37
0
파일: sentry.py 프로젝트: AgnitumuS/show_tv
def setup(dsn, level, propagate_sentry_errors=False):
    client = make_client(dsn, False)

    from raven.handlers.logging import SentryHandler
    global handler
    handler = SentryHandler(client)
    handler.setLevel(level)
    handler.dsn = dsn

    from raven.conf import setup_logging
    kwargs = {}
    if propagate_sentry_errors:
        kwargs["exclude"] = []
    setup_logging(handler, **kwargs)
예제 #38
0
def lambda_handler(event, context):
    logger = logging.getLogger()
    logger.debug(event)
    raven_client = Raven_client()  # Needs SENTRY_DSN env var
    sentry_handler = SentryHandler(raven_client)
    sentry_handler.setLevel(logging.WARNING)
    setup_logging(sentry_handler)
    logger.setLevel(logging.INFO)
    enable_xray()
    try:
        EventProcesser().process(event)
    except Exception as e:
        logger.error('error processing event'.format(event))
        raise e
예제 #39
0
def install_sentry_logger():
    try:
        import raven
    except ImportError:
        logging.warning(
            'Unable to find raven library. Sentry integration disabled.')
        return

    from raven.conf import setup_logging
    from raven.handlers.logging import SentryHandler

    client = raven.Client()
    handler = SentryHandler(client, level=logging.WARN)
    setup_logging(handler)
예제 #40
0
파일: sentry.py 프로젝트: alkadis/vcv
    def __init__(self, app, config):
        self.app = app

        dsn = aconfig.get('adhocracy.sentry.dsn', config=config)
        if not dsn:
            raise Exception(
                'Sentry misconfigured. Please add adhocracy.sentry.dsn '
                'to your adhocracy config.')

        self.client = Client(dsn)

        handler = SentryHandler(
            self.client, level=aconfig.get('adhocracy.sentry.loglevel'))
        setup_logging(handler)
예제 #41
0
def init_raven_client(dsn):
    global _sentry
    _sentry = raven.Client(
        dsn=dsn,
        transport=raven.transport.threaded_requests.
        ThreadedRequestsHTTPTransport,
        ignore_exceptions={KeyboardInterrupt, HTTPException},
        logging=True,
    )
    sentry_errors_logger = logging.getLogger("sentry.errors")
    sentry_errors_logger.addHandler(logging.StreamHandler())
    handler = SentryHandler(_sentry)
    handler.setLevel(logging.ERROR)
    setup_logging(handler)
예제 #42
0
	def __init__(self, **kwargs):
		self.public_key = "c315978776e34ccc816da619bc3c2f28"
		self.secret_key = "56fa120c52db4bdd95c910ae2d251128"
		self.project_id = 4

		self.dsn = "http://%s:%s@sentry:9000/%s" % (
			self.public_key,
			self.secret_key,
			self.project_id
		)
		raven.Client.__init__(self, self.dsn, auto_log_stacks=True, **kwargs)

		self.handler = SentryHandler(self)
		setup_logging(self.handler)
예제 #43
0
    def gen_logger(self, log_path):
        # set produce log level
        self.logger.setLevel(self.level)

        # gen two handler and set it on the logger
        handler_info = gen_handler(log_path)
        handler_error = gen_handler(log_path, error=True)
        self.logger.addHandler(handler_info)
        self.logger.addHandler(handler_error)
        # inti sentry
        handler.setLevel(logging.ERROR)
        setup_logging(handler)

        return self.logger
예제 #44
0
 def __init__(self, pool, cursor):
     if not config.get('sentry_dsn', False):
         raise osv.except_osv(
             _(u'Error'),
             _(u'No sentry DSN configured in config file.')
         )
     processors = (
         'raven.processors.SanitizePasswordsProcessor',
         'raven_sanitize_openerp.OpenerpPasswordsProcessor'
     )
     self.client = Client(dsn=config['sentry_dsn'], processors=processors)
     handler = SentryHandler(self.client)
     setup_logging(handler)
     super(SentrySetup, self).__init__(pool, cursor)
예제 #45
0
    def __init__(self,
                 dsn=None,
                 client=None,
                 logging=True,
                 breadcrumbs=True,
                 **kwargs):

        self.dsn = dsn
        self.logging = logging
        self.breadcrumbs = breadcrumbs
        self.client = client or make_client(kwargs)

        if logging:
            setup_logging(SentryHandler(self.client))
예제 #46
0
파일: parse.py 프로젝트: izacus/newsbuddy
def parse_news():
    if settings.SENTRY_CONNECTION_STRING is not None:
        from raven import Client
        from raven.handlers.logging import SentryHandler
        from raven.conf import setup_logging
        logging.basicConfig(level=logging.WARN)
        client = Client(settings.SENTRY_CONNECTION_STRING)
        handler = SentryHandler(client)
        setup_logging(handler)
    else:
        logging.basicConfig(level=logging.DEBUG)

    existing_ids = db.news.get_latest_ids(600)
    tasks.scrape_news(existing_ids)
예제 #47
0
파일: args.py 프로젝트: Marius786/gitfs
    def check_args(self, args):
        # check allow_other and allow_root
        if args.allow_other:
            args.allow_root = False
        else:
            args.allow_root = True

        # check log_level
        if args.debug:
            args.log_level = 'debug'

        # setup logging
        if args.log != "syslog":
            if args.log in ('-', '/dev/stdout'):
                handler = StreamHandler(sys.stdout)
            else:
                handler = TimedRotatingFileHandler(args.log, when="midnight")
            handler.setFormatter(Formatter(fmt='%(asctime)s %(threadName)s: '
                                           '%(message)s',
                                           datefmt='%B-%d-%Y %H:%M:%S'))
        else:
            if sys.platform == 'darwin':
                handler = SysLogHandler(address="/var/run/syslog")
            else:
                handler = SysLogHandler(address="/dev/log")
            logger_fmt = 'GitFS on {mount_point} [%(process)d]: %(threadName)s: '\
                         '%(message)s'.format(mount_point=args.mount_point)
            handler.setFormatter(Formatter(fmt=logger_fmt))

        if args.sentry_dsn != '':
            from raven.conf import setup_logging
            from raven.handlers.logging import SentryHandler

            sentry_handler = SentryHandler(args.sentry_dsn)
            sentry_handler.setLevel("ERROR")
            setup_logging(sentry_handler)
            log.addHandler(sentry_handler)

        handler.setLevel(args.log_level.upper())
        log.setLevel(args.log_level.upper())
        log.addHandler(handler)

        # set cache size
        lru_cache.maxsize = args.cache_size

        # return absolute repository's path
        args.repo_path = os.path.abspath(args.repo_path)

        return args
예제 #48
0
 def __init__(self, config_file, logger):
     self.config = config_from_file(config_file)
     self.info = config_from_file("info.json")
     self.logger = logger
     super(Bot, self).__init__(command_prefix=get_prefix,
                               shard_count=self.config.shard_count)
     self.init_databases()
     self.modlog = ModLog(self)
     if self.config.sentry_dsn != None:
         self.sentry = Client(self.config.sentry_dsn)
         sentry_handler = SentryHandler(self.sentry)
         sentry_handler.setLevel(logging.ERROR)
         setup_logging(sentry_handler)
     else:
         self.sentry = None
예제 #49
0
    def _init_raven(self):
        from raven.conf import EXCLUDE_LOGGER_DEFAULTS, setup_logging
        from raven.handlers.logging import SentryHandler

        # Initialize Raven only if SENTRY_DSN setting is defined.
        if not self.config.get('SENTRY_DSN'):
            return

        sentry.init_app(self)
        handler = SentryHandler(sentry.client)

        setup_logging(handler, exclude=EXCLUDE_LOGGER_DEFAULTS + (
            'celery',
            'requests',
        ))
예제 #50
0
def init_logdrain(logdrain_url=logdrain_url,
                  logdrain_logformat=logdrain_logformat):
    if logdrain_url.startswith('syslog'):
        handler = get_syslog_handler(logdrain_url)
    else:
        raise NotImplementedError(
            'Could not initialize LOGDRAIN_URL "%s". Only "syslog" is supported for now'
            % logdrain_url)

    if logdrain_logformat:
        formatter = logging.Formatter(logdrain_logformat, "%Y-%m-%dT%H:%M:%SZ")
        handler.setFormatter(formatter)

    setup_logging(handler, exclude=[])  # Sentry made it so easy! Thanks S2
    return handler
예제 #51
0
파일: sentry.py 프로젝트: qip/Albireo
 def scheduler_sentry(self):
     sentry_dsn_dict = SentryWrapper.get_config('sentry_dsn')
     if sentry_dsn_dict is None:
         return
     scheduler_dsn = sentry_dsn_dict.get('scheduler')
     if scheduler_dsn is None:
         return
     from raven import Client
     from raven.handlers.logging import SentryHandler
     from raven.conf import setup_logging
     self.client = Client(dsn=scheduler_dsn)
     self.handler = SentryHandler(self.client)
     self.handler.setLevel(logging.ERROR)
     # finish the job
     setup_logging(self.handler)
예제 #52
0
 def test_basic_already_configured(self):
     with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
         handler = mock.Mock()
         logger = getLogger()
         logger.handlers = [handler]
         result = setup_logging(handler)
         self.assertFalse(result)
예제 #53
0
 def test_basic_already_configured(self):
     with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
         handler = mock.Mock()
         logger = getLogger()
         logger.handlers = [handler]
         result = setup_logging(handler)
         self.assertFalse(result)
예제 #54
0
 def test_basic_not_configured(self):
     with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
         logger = getLogger()
         logger.handlers = []
         handler = mock.Mock()
         result = setup_logging(handler)
         self.assertTrue(result)
def create_app():
    app = Flask(__name__)
    if config.is_prod_mode():
        app.config.from_object('server.config.ProductionConfig')
    else:
        app.config.from_object('server.config.DevelopmentConfig')
    # Set up sentry logging
    if app.config['SENTRY_DSN'] is not None:
        handler = SentryHandler(app.config['SENTRY_DSN'])
        handler.setLevel(logging.ERROR)
        setup_logging(handler)
        Sentry(app, dsn=app.config['SENTRY_DSN'])
        logger.info('Logging to Sentry')
    else:
        logger.info('No Sentry logging')
    return app
예제 #56
0
 def test_basic_not_configured(self):
     with mock.patch('logging.getLogger', spec=logging.getLogger) as getLogger:
         logger = getLogger()
         logger.handlers = []
         handler = mock.Mock()
         result = setup_logging(handler)
         self.assertTrue(result)
예제 #57
0
def main():
    import logging
    logging.basicConfig(format=LOG_FORMAT)
    logging.getLogger('werkzeug').setLevel(logging.INFO)

    from hambar.app import create_app, create_manager
    app = create_app()

    SENTRY_DSN = app.config.get('SENTRY_DSN')
    if SENTRY_DSN:
        from raven.conf import setup_logging
        from raven.handlers.logging import SentryHandler
        setup_logging(SentryHandler(SENTRY_DSN, level=logging.WARN))

    manager = create_manager(app)
    manager.run()
예제 #58
0
    def __init__(self, config=None):
        self.config = {
            'capture_timeout_warnings':
            boolval(os.environ.get('SENTRY_CAPTURE_TIMEOUTS', True)),
            'timeout_warning_threshold':
            float(os.environ.get('SENTRY_TIMEOUT_THRESHOLD', 0.50)),
            'capture_memory_warnings':
            boolval(os.environ.get('SENTRY_CAPTURE_MEMORY', True)),
            'memory_warning_threshold':
            float(os.environ.get('SENTRY_MEMORY_THRESHOLD', 0.75)),
            'capture_unhandled_exceptions':
            boolval(os.environ.get('SENTRY_CAPTURE_UNHANDLED', True)),
            'auto_bread_crumbs':
            boolval(os.environ.get('SENTRY_AUTO_BREADCRUMBS', True)),
            'capture_errors':
            boolval(os.environ.get('SENTRY_CAPTURE_ERRORS', True)),
            'filter_local':
            boolval(os.environ.get('SENTRY_FILTER_LOCAL', True)),
            'is_local':
            os.environ.get('IS_OFFLINE', False)
            or os.environ.get('IS_LOCAL', False),
            'logging':
            boolval(os.environ.get('SENTRY_CAPTURE_LOGS', True)),
            'log_level':
            extract_log_level_from_environment('SENTRY_LOG_LEVEL',
                                               logging.WARNING),
            'enabled':
            boolval(os.environ.get('SENTRY_ENABLED', True)),
        }
        self.config.update(config or {})

        # check for local environment
        if self.config['filter_local'] and self.config['is_local']:
            logger.warning('Sentry is disabled in local environment')
            self.config["enabled"] = False
            return

        if self.config.get('raven_client'):
            assert self.config.get('raven_client') and not isinstance(
                self.config.get('raven_client'), Client)
        else:
            self.config['raven_client'] = configure_raven_client(self.config)

        if self.config['logging'] and self.config['raven_client']:
            handler = SentryHandler(self.config['raven_client'])
            handler.setLevel(self.config['log_level'])
            setup_logging(handler)