7

I managed to install sentry successfully and I can see the sentry interface webservice at localhost and doing a

raven test http://jsifslkdjfklsdfjklsdjfklMYCODE 

works, the tests shows up in the interface.

The problem is I can't find any examples or documentation on what exactly should I put on my views and my settings.

I know I have to add to my INSTALLED_APPS

'sentry', 'raven.contrib.django',

And I also added

SENTRY_DNS = 'http://jsifslkdjfklsdfjklsdjfklMYCODE'

This next two lines appear in the docs but it doesnt say where do they go

from raven.contrib.django.models import client
client.captureException()

I tried in settings.py but still I can't get my views to log anything. I also added this

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

And in my views I added this:

import logging
logger = logging.getLogger()

def home(request,template_name): 
    logger.error('There was some crazy error lol', exc_info=True, extra={'request': request, })
    return render_to_response(template_name,context, context_instance=RequestContext(request))

I have no other code related to logging apart from what you see here, What am I missing?

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
grillermo
  • 71
  • 1
  • 3

2 Answers2

8

Your 'raven' logger is not actually using the sentry handler, but only writing to 'console'. Had the same problem. The documentation for raven/sentry lacks a good writer.

change your raven logger to:

'raven': {
            'level': 'DEBUG',
            'handlers': ['console', 'sentry'],
            'propagate': False,
         },

and make sure you use it as logger:

logger = logging.getLogger('raven')
RickyA
  • 15,465
  • 5
  • 71
  • 95
  • 7
    The 'raven' logger refers to the raven package, and I'd presume that it's put there so that raven internal errors don't get sent back to raven, resulting in an infinite loop. You should create your own logger 'myapp' that has it's own entry in settings.py LOGGING. – joerick Sep 26 '13 at 10:45
1

I had to use this monstruosity on my settings.py:

import logging
# from raven.contrib.django.handlers import SentryHandler 
from raven.handlers.logging import SentryHandler

logging.getLogger().setLevel(logging.INFO)
logger = logging.getLogger()# ensure we havent already registered the handler
handler = SentryHandler('http://13d06dad246d4fe6a180ef9b15151a13:eb46a6d724df4327a8cc04d9d3cfad37@sentry.bandtastic.pagekite.me/1')
logger.addHandler(handler)
# Add StreamHandler to sentry's default so you can catch missed exceptions
logger = logging.getLogger('sentry.errors')
logger.propagate = False
logger.addHandler(logging.StreamHandler())


from raven.conf import setup_logging
setup_logging(handler)

And in my views i can use a simple

import logging
logger = logging.getLogger(__name__)
def home(request,context={},template_name=None):
    logger.info(str(request), exc_info=True)
    return render_to_response(template_name,context, context_instance=RequestContext(request))

I tried many settings.

Eugene Lazutkin
  • 43,776
  • 8
  • 49
  • 56
Guillermo Siliceo Trueba
  • 4,251
  • 5
  • 34
  • 47