@@ -0,0 +1,1883 @@
+# -*- coding: utf-8 -*-%0Au%22%22%22%0ACopyright 2012-2014 Olivier Cort%C3%A8s %3Coc@1flow.io%3E.%0A%0AThis file is part of the 1flow project.%0A%0A1flow is free software: you can redistribute it and/or modify%0Ait under the terms of the GNU Affero General Public License as%0Apublished by the Free Software Foundation, either version 3 of%0Athe License, or (at your option) any later version.%0A%0A1flow is distributed in the hope that it will be useful,%0Abut WITHOUT ANY WARRANTY; without even the implied warranty of%0AMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0AGNU Affero General Public License for more details.%0A%0AYou should have received a copy of the GNU Affero General Public%0ALicense along with 1flow.  If not, see http://www.gnu.org/licenses/%0A%0A%22%22%22%0Aimport sys%0A%0Aimport logging%0Aimport traceback%0A%0Afrom django.conf import settings%0Afrom django.core.exceptions import MiddlewareNotUsed%0A%0ALOGGER = logging.getLogger(__name__)%0A%0A%0Aclass PrintExceptionMiddleware(object):%0A%0A    u%22%22%22 Print exceptions on console (in DEBUG mode only).%0A%0A%0A    .. note:: this middleware disables itself %E2%80%94%C2%A0by%0A        raising :class:%60MiddlewareNotUsed%60 %C2%A0%E2%80%94 if %60%60settings.DEBUG%60%60%0A        is %60%60False%60%60.%0A%0A    Source: http://stackoverflow.com/a/13061129/654755 and%0A    Django documentation%0A    %22%22%22%0A%0A    def __init__(self):%0A        %22%22%22 Disable this middleware if not in DEBUG mode. %22%22%22%0A%0A        if not settings.DEBUG:%0A            raise MiddlewareNotUsed%0A%0A        LOGGER.debug(%0A            u'%5Cn%3C%3C%3C%3C%3E%3E%3E%3E PrintExceptionMiddleware is active. %3C%3C%3C%3C%3E%3E%3E%3E%5Cn')%0A%0A    def process_response(self, request, response):%0A        %22%22%22 Print exception if error code is 50x. %22%22%22%0A%0A        if response.status_code in (500, 501, 502, 503, ):%0A            try:%0A                LOGGER.debug(u'%5Cn'.join(%0A                    traceback.format_exception(*sys.exc_info())))%0A%0A            except:%0A                LOGGER.debug(traceback.format_exc())%0A%0A        return response%0A

Add a print_exc() middleware, I'm very tired of needing to wait for sentry to process them on the temporarily-slow distant server.