How to use clock / raven in django views

I managed to install the chat successfully, and I can see the clock interface web service on localhost and do

raven test http://jsifslkdjfklsdfjklsdjfklMYCODE 

works, tests are displayed in the interface.

The problem is that I can not find any examples or documentation about what exactly I should use for my views and my settings.

I know what I need to add to my INSTALLED_APPS

'guard', 'Raven.contrib.django',

And I also added

 SENTRY_DNS = 'http://jsifslkdjfklsdfjklsdjfklMYCODE' 

The next two lines appear in the documents, but they do not say where they are going.

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

I tried in settings.py, but still I can't get my views to write 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 registration other than what you see here. What am I missing?

+7
source share
2 answers

Your "raven" logger doesn’t actually use a clock engine, it only writes the "console". Had the same problem. There is no good writer in the documentation for the raven / guard.

change your logger to:

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

and make sure you use it as a registrar:

 logger = logging.getLogger('raven') 
+7
source

I had to use this monster in my .py settings:

 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 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 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 a lot of settings.

+1
source

All Articles