Commit 5f39a03d authored by Michal Čihař's avatar Michal Čihař

Add shared error logging code

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent f45855bb
...@@ -22,10 +22,18 @@ from django.core.exceptions import ImproperlyConfigured ...@@ -22,10 +22,18 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.cache import cache from django.core.cache import cache
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
from django.conf import settings
from importlib import import_module from importlib import import_module
import os import os
import urlparse import urlparse
import hashlib import hashlib
import weblate
try:
import rollbar
HAS_ROLLBAR = True
except ImportError:
HAS_ROLLBAR = False
PLURAL_SEPARATOR = '\x1e\x1e' PLURAL_SEPARATOR = '\x1e\x1e'
...@@ -214,3 +222,19 @@ def cleanup_path(path): ...@@ -214,3 +222,19 @@ def cleanup_path(path):
if path.startswith('/'): if path.startswith('/'):
path = path[1:] path = path[1:]
return path return path
def report_error(error, exc_info, request=None, extra_data=None):
"""Wrapper for error reporting
This can be used for store exceptions in error reporting solutions as
rollbar while handling error gracefully and giving user cleaner message.
"""
if HAS_ROLLBAR and hasattr(settings, 'ROLLBAR'):
rollbar.report_exc_info(exc_info, request, extra_data=extra_data)
weblate.logger.error(
'Handled exception %s: %s',
error.__class__.__name__,
str(error)
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment