Repository: encode/django-rest-framework

Issue:
Tracebacks not printed on console v 3.4.4 | Logger
With 3.4.4 Tracebacks are not being printed on console. For version 3.3.3 - 3.4.3, Tracebacks were/are printed fine on console. But in version 3.4.4 it prints only in the browser.

This may be the reason for the issue [#4172](https://github.com/tomchristie/django-rest-framework/pull/4172)

Using - Django v1.9.9
Here is my logger config...

```

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '[%(levelname)s] %(asctime)s  | %(module)s %(funcName)s %(lineno)d | PID - %(process)d, Thread - %(thread)d | %(message)s'
        },
    },
    'handlers': {
        'general': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/app/general.log',
            'maxBytes': 1024*1024*10,
            'backupCount': 10,
            'formatter': 'verbose',
        },
        'request': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/app/request.log',
            'maxBytes': 1024*1024*10,
            'backupCount': 10,
            'formatter': 'verbose',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        }
    },
    'loggers': {
        '': {
            'handlers': ['console', 'general'],
            'level': 'DEBUG',
        },
        'django.request': {
            'handlers': ['console', 'request'],
            'level': 'DEBUG',
            'propagate': False,
        }
    }
}
```



Discussion:

Resolving patch:
diff --git a/rest_framework/request.py b/rest_framework/request.py
--- a/rest_framework/request.py
+++ b/rest_framework/request.py
@@ -391,3 +391,8 @@ def QUERY_PARAMS(self):
             '`request.QUERY_PARAMS` has been deprecated in favor of `request.query_params` '
             'since version 3.0, and has been fully removed as of version 3.2.'
         )
+
+    def force_plaintext_errors(self, value):
+        # Hack to allow our exception handler to force choice of
+        # plaintext or html error responses.
+        self._request.is_ajax = lambda: value
diff --git a/rest_framework/views.py b/rest_framework/views.py
--- a/rest_framework/views.py
+++ b/rest_framework/views.py
@@ -3,17 +3,14 @@
 """
 from __future__ import unicode_literals
 
-import sys
-
 from django.conf import settings
 from django.core.exceptions import PermissionDenied
 from django.db import models
 from django.http import Http404
-from django.http.response import HttpResponse, HttpResponseBase
+from django.http.response import HttpResponseBase
 from django.utils import six
 from django.utils.encoding import smart_text
 from django.utils.translation import ugettext_lazy as _
-from django.views import debug
 from django.views.decorators.csrf import csrf_exempt
 from django.views.generic import View
 
@@ -95,11 +92,6 @@ def exception_handler(exc, context):
         set_rollback()
         return Response(data, status=status.HTTP_403_FORBIDDEN)
 
-    # throw django's error page if debug is True
-    if settings.DEBUG:
-        exception_reporter = debug.ExceptionReporter(context.get('request'), *sys.exc_info())
-        return HttpResponse(exception_reporter.get_traceback_html(), status=500)
-
     return None
 
 
@@ -439,11 +431,19 @@ def handle_exception(self, exc):
         response = exception_handler(exc, context)
 
         if response is None:
-            raise
+            self.raise_uncaught_exception(exc)
 
         response.exception = True
         return response
 
+    def raise_uncaught_exception(self, exc):
+        if settings.DEBUG:
+            request = self.request
+            renderer_format = getattr(request.accepted_renderer, 'format')
+            use_plaintext_traceback = renderer_format not in ('html', 'api', 'admin')
+            request.force_plaintext_errors(use_plaintext_traceback)
+        raise
+
     # Note: Views are made CSRF exempt from within `as_view` as to prevent
     # accidental removal of this exemption in cases where `dispatch` needs to
     # be overridden.


Test patch: