miércoles, 30 de mayo de 2012

Django, Sentry, Redis, Raven

So you have sentry working, you can see its nice web interface, but can't log anything for shiiiiz.

Its been a pain installing the logging and async tasks setup, i sort of did it in parallel.
The hardest part wasnt actually installing the setup, it was getting my views to actually log to sentry.
The documentation is pretty bad, so i'm putting my settings here so hopefully somebody suffers less.

In my settings i added this monstruosity.

import logging

from raven.handlers.logging import SentryHandler

logging.getLogger().setLevel(logging.INFO)
logger = logging.getLogger()# ensure we havent already registered the handler
handler = SentryHandler('http://the magic url you get from sentry')
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
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))

And thats it.

lunes, 21 de mayo de 2012

javascript parseInt

parseInt is a javascript function that can't be relied to return NaN in some strings that are not numbers
parseInt('12lol')
returns 12
parseInt('lol12')
returns Nan

A more reliable function to do this is Number()
Number('12lol')
returns Nan
Number('293.2')
returns 293.2

parseFloat has the same defect, don't rely on those.