Merge pull request #726 from radzinzki/allow_exclude_list_on_creation
Allow logging exclusions during object creation and `init_app`
This commit is contained in:
commit
3e14b36050
|
@ -30,7 +30,8 @@ You can optionally configure logging too::
|
|||
|
||||
import logging
|
||||
from raven.contrib.flask import Sentry
|
||||
sentry = Sentry(app, logging=True, level=logging.ERROR)
|
||||
sentry = Sentry(app, logging=True, level=logging.ERROR, \
|
||||
logging_exclusions=("logger1", "logger2", ...))
|
||||
|
||||
Building applications on the fly? You can use Raven's ``init_app`` hook::
|
||||
|
||||
|
@ -48,7 +49,8 @@ You can pass parameters in the ``init_app`` hook::
|
|||
def create_app():
|
||||
app = Flask(__name__)
|
||||
sentry.init_app(app, dsn='___DSN___', logging=True,
|
||||
level=logging.ERROR)
|
||||
level=logging.ERROR,
|
||||
logging_exclusions=("logger1", "logger2", ...))
|
||||
return app
|
||||
|
||||
Settings
|
||||
|
|
|
@ -132,3 +132,13 @@ message within Sentry::
|
|||
logger.error('There was some %s error', 'crazy')
|
||||
logger.error('There was some %s error', 'fun')
|
||||
logger.error('There was some %s error', 1)
|
||||
|
||||
Exclusions
|
||||
~~~~~~~~~~
|
||||
|
||||
You can also configure some logging exclusions during setup. These loggers
|
||||
will not propagate their logs to the Sentry handler.
|
||||
|
||||
from raven.conf import setup_logging
|
||||
|
||||
setup_logging(handler, exclude=("logger1", "logger2", ...))
|
||||
|
|
|
@ -103,10 +103,11 @@ class Sentry(object):
|
|||
# TODO(dcramer): the client isn't using local context and therefore
|
||||
# gets shared by every app that does init on it
|
||||
def __init__(self, app=None, client=None, client_cls=Client, dsn=None,
|
||||
logging=False, level=logging.NOTSET, wrap_wsgi=None,
|
||||
register_signal=True):
|
||||
logging=False, logging_exclusions=None, level=logging.NOTSET,
|
||||
wrap_wsgi=None, register_signal=True):
|
||||
self.dsn = dsn
|
||||
self.logging = logging
|
||||
self.logging_exclusions = logging_exclusions
|
||||
self.client_cls = client_cls
|
||||
self.client = client
|
||||
self.level = level
|
||||
|
@ -238,7 +239,8 @@ class Sentry(object):
|
|||
self.client.context.clear()
|
||||
return response
|
||||
|
||||
def init_app(self, app, dsn=None, logging=None, level=None, wrap_wsgi=None,
|
||||
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
|
||||
|
@ -262,11 +264,18 @@ class Sentry(object):
|
|||
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:
|
||||
setup_logging(SentryHandler(self.client, level=self.level))
|
||||
kwargs = {}
|
||||
if self.logging_exclusions is not None:
|
||||
kwargs['exclude'] = self.logging_exclusions
|
||||
|
||||
setup_logging(SentryHandler(self.client, level=self.level), **kwargs)
|
||||
|
||||
if self.wrap_wsgi:
|
||||
app.wsgi_app = SentryMiddleware(app.wsgi_app, self.client)
|
||||
|
|
|
@ -270,6 +270,19 @@ class FlaskTest(BaseTest):
|
|||
assert self.middleware.last_event_id == event_id
|
||||
assert g.sentry_event_id == event_id
|
||||
|
||||
def test_logging_setup_with_exclusion_list(self):
|
||||
app = Flask(__name__)
|
||||
raven = TempStoreClient()
|
||||
|
||||
Sentry(app, client=raven, logging=True,
|
||||
logging_exclusions=("excluded_logger",))
|
||||
|
||||
excluded_logger = logging.getLogger("excluded_logger")
|
||||
self.assertFalse(excluded_logger.propagate)
|
||||
|
||||
some_other_logger = logging.getLogger("some_other_logger")
|
||||
self.assertTrue(some_other_logger.propagate)
|
||||
|
||||
|
||||
class FlaskLoginTest(BaseTest):
|
||||
|
||||
|
|
Loading…
Reference in New Issue