+def error_handler(request):
+
+ stacktrace = "".join(["\t\t%s\n" % l for l in traceback.format_exc().split("\n")])
+
+ try:
+ log_msg = """
+ error executing request:
+ PATH: %(path)s
+ USER: %(user)s
+ METHOD: %(method)s
+ POST PARAMETERS:
+ %(post)s
+ GET PARAMETERS:
+ %(get)s
+ HTTP HEADERS:
+ %(headers)s
+ COOKIES:
+ %(cookies)s
+ EXCEPTION INFO:
+ %(stacktrace)s
+ """ % {
+ 'path': request.path,
+ 'user': request.user.is_authenticated() and ("%s (%s)" % (request.user.username, request.user.id)) or "<anonymous>",
+ 'method': request.method,
+ 'post': request.POST and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.POST.items()]) or "None",
+ 'get': request.GET and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.GET.items()]) or "None",
+ 'cookies': request.COOKIES and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.COOKIES.items()]) or "None",
+ 'headers': request.META and "".join(["\t\t%s: %s\n" % (k, v) for k, v in request.META.items()]) or "None",
+ 'stacktrace': stacktrace
+ }
+ except:
+ log_msg = "error executing request:\n%s" % stacktrace
+
+
+ logging.error(log_msg)
+ return HttpResponseIntServerError(request)