def update_video_feed(video_feed_id): try: video_feed = VideoFeed.objects.get(pk=video_feed_id) video_feed.update() except VideoFeed: msg = '**update_video_feed**. VideoFeed does not exist. ID: %s' % video_feed_id client.create_from_text(msg, logger='celery')
def send_new_message_notification(message_id): try: message = Message.objects.get(pk=message_id) except Message.DoesNotExist: msg = '**send_new_message_notification**. Message does not exist. ID: %s' % message_id client.create_from_text(msg, logger='celery') return user = message.user if not user.email or not user.is_active or not user.changes_notification: return to = "%s <%s>" % (user, user.email) subject = _(u"%(author)s sent you a message on Universal Subtitles: %(subject)s") subject = subject % { 'author': message.author, 'subject': message.subject } context = { "message": message, "domain": Site.objects.get_current().domain } send_templated_email(to, subject, "messages/email/message_received.html", context)
def js_error_handler(request, *args, **kwargs): message = request.POST.get('message', None) url = request.POST.get('url', None) client.create_from_text(message, level=logging.ERROR, url=url, request=request) return HttpResponse('true')
def sentry_js_exception(request, stackInfo, url): """ Logs an exception in Sentry. POST the following JSON structure: { "url": "http://example.com/foo/bar", "stackInfo": stack // a JSONified "stack info" object that TraceKit provides. } (See: https://github.com/csnover/TraceKit) For now we just log the JSON string. In the future we could format it into something Sentry understands better. """ def stringify(obj): return util.dumps(obj, indent=2) stack_info = stackInfo message = unicode(stack_info.get('message', 'Unknown error')) try: message += '\n' + ' '*100 + '\n\nStack trace:\n\n' + stringify(stack_info['stack']) except KeyError: pass kwargs = { 'url': url, 'view': stack_info.get('name', 'JavaScript'), # The main title of this error. 'level': logging.ERROR, 'logger': 'javascript', } client.create_from_text(message, **kwargs)
def send_new_message_notification(message_id): try: message = Message.objects.get(pk=message_id) except Message.DoesNotExist: msg = '**send_new_message_notification**. Message does not exist. ID: %s' % message_id client.create_from_text(msg, logger='celery') return user = message.user if not user.email or not user.is_active or not user.changes_notification: return to = "%s <%s>" % (user, user.email) subject = _( u"%(author)s sent you a message on Universal Subtitles: %(subject)s") subject = subject % {'author': message.author, 'subject': message.subject} context = { "message": message, "domain": Site.objects.get_current().domain, "STATIC_URL": settings.STATIC_URL, } send_templated_email(to, subject, "messages/email/message_received.html", context)
def sentry_js_exception(request, stackInfo, url): """ Logs an exception in Sentry. POST the following JSON structure: { "url": "http://example.com/foo/bar", "stackInfo": stack // a JSONified "stack info" object that TraceKit provides. } (See: https://github.com/csnover/TraceKit) For now we just log the JSON string. In the future we could format it into something Sentry understands better. """ def stringify(obj): return util.dumps(obj, indent=2) stack_info = stackInfo message = unicode(stack_info.get('message', 'Unknown error')) try: message += '\n' + ' ' * 100 + '\n\nStack trace:\n\n' + stringify( stack_info['stack']) except KeyError: pass kwargs = { 'url': url, 'view': stack_info.get('name', 'JavaScript'), # The main title of this error. 'level': logging.ERROR, 'logger': 'javascript', } client.create_from_text(message, **kwargs)
def log_error(message, level=logging.ERROR): if sentry_client is not None: sentry_client.create_from_text(message, level=level) else: print "If sentry was set up we would log the following", \ message