Commits

Stefano Rivera committed d3e0388

Don't prepare a report if we aren't going to be using it

  • Participants
  • Parent commits 5b250a5

Comments (0)

Files changed (1)

File dogslow/__init__.py

                         },
                     })
 
+            write_log = getattr(settings, 'DOGSLOW_WRITE_LOG', True)
+            email_to = getattr(settings, 'DOGSLOW_EMAIL_TO', None)
+            email_from = getattr(settings, 'DOGSLOW_EMAIL_FROM', None)
+            logger_name = getattr(settings, 'DOGSLOW_LOGGER', None)
+
+            # Do we want to do anything else?
+            if (not write_log
+                    and not (email_to and email_from)
+                    and not logger_name):
+                return
+
             req_string = '%s %s://%s%s' % (
                 request.META.get('REQUEST_METHOD'),
                 request.META.get('wsgi.url_scheme', 'http'),
             output = output.encode('utf-8')
 
             # dump to file:
-            write_log = getattr(settings, 'DOGSLOW_WRITE_LOG', True)
             if write_log:
                 fd, fn = tempfile.mkstemp(prefix='slow_request_',
                                           suffix='.log',
                     os.close(fd)
 
             # and email?
-            email_to = getattr(settings, 'DOGSLOW_EMAIL_TO', None)
-            email_from = getattr(settings, 'DOGSLOW_EMAIL_FROM', None)
             if email_to is not None and email_from is not None:
                 em = EmailMessage('Slow Request Watchdog: %s' %
                                   req_string.encode('utf-8'),
                 em.send(fail_silently=True)
 
             # and a custom logger:
-            logger_name = getattr(settings, 'DOGSLOW_LOGGER', None)
             log_level = getattr(settings, 'DOGSLOW_LOG_LEVEL', 'WARNING')
             if logger_name is not None:
                 log_level = logging.getLevelName(log_level)