Django Entrance with Raven and Sentinel

I might be a little late for the train, but I wanted to use Sentry and Raven to enter Django.

I set the sentry and raven to the point where I ran the test for the raven, and it works.

So now I want to send my debug messages to the sentry, but how would I do this?

settings.py

RAVEN_CONFIG = {
    'dsn': 'http://code4@mydomain:9000/2',
    # If you are using git, you can also automatically configure the
    # release based on the git info.
    'release': raven.fetch_git_sha(BASE_DIR),
}

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
    },
    'handlers': {
        'sentry': {
            'level': 'WARNING',
            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
        },
        'console': {
            'level': 'WARNING',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django': {
            'handlers': ['sentry'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'raven': {
            'level': 'DEBUG',
            'handlers': ['sentry'],
            'propagate': False,
        },
        'sentry.errors': {
            'level': 'DEBUG',
            'handlers': ['sentry'],
            'propagate': False,
        },
    }
}

view.py

import logger
from raven.contrib.django.models import get_client


client = get_client()
client.captureException()

logger = logging.getLogger(__name__)



def my_view(request):

   [...]
    logger.error('There was some crazy error', exc_info=True, extra={
    # Optionally pass a request and we'll grab any information we can
    'request': request,
    })
    [...]

At this point, it just logs errors and exceptions, but will not send me this error message ...

How to use the crow and sentry? The docs don't help, and my google foo left me too. Any tips or helpful lessons?

+4
source share
1 answer

3 : django, raven sentry.errors. logging.getLogger(__name__), "", ___name__ .

raven...

logger = logging.getLogger('raven')
logger.debug('Hola!')

... :

LOGGING = {
    # ...
    'loggers': {
        # ...
        'yourapp': {
            'level': 'debug',
            'handlers': ['sentry'],
            'propagate': False,
        },
    }
}

yourapp/views.py:

logger = logging.getLogger(__name__)
logger.debug('Hola!')
+7

Source: https://habr.com/ru/post/1623819/


All Articles