From dfaf45b2b66685b303318269b5ce5159089a0b11 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 6 Dec 2015 10:53:17 -0800 Subject: [PATCH] Wrap Django runserver to prevent spammy logging. Django's `manage.py runserver` prints a relatively low-information log line for every request of the form: [14/Dec/2015 00:43:06]"GET /static/js/message_list.js HTTP/1.0" 200 21969 This is pretty spammy, especially given that we already have our own middleware printing a more detailed version of the same log lines: 2015-12-14 00:43:06,935 INFO 127.0.0.1 GET 200 0ms /static/js/message_list.js (unauth via ?) Since runserver doesn't have support controlling whether these log lines are printed, we wrap it with a small bit of code that silences the log lines for 200/304 requests (aka the uninteresting ones). --- tools/run-dev.py | 2 +- zerver/management/commands/rundjango.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 zerver/management/commands/rundjango.py diff --git a/tools/run-dev.py b/tools/run-dev.py index 2702658a03..67b1614d07 100755 --- a/tools/run-dev.py +++ b/tools/run-dev.py @@ -77,7 +77,7 @@ os.setpgrp() # zulip/urls.py. cmds = [['./tools/compile-handlebars-templates', 'forever'], ['./tools/webpack', 'watch'], - ['python', 'manage.py', 'runserver', '--nostatic'] + + ['python', 'manage.py', 'rundjango'] + manage_args + ['localhost:%d' % (django_port,)], ['python', 'manage.py', 'runtornado'] + manage_args + ['localhost:%d' % (tornado_port,)], diff --git a/zerver/management/commands/rundjango.py b/zerver/management/commands/rundjango.py new file mode 100644 index 0000000000..b3f65bb521 --- /dev/null +++ b/zerver/management/commands/rundjango.py @@ -0,0 +1,13 @@ +# Wrapper around Django's runserver to allow filtering logs. + +from django.core.servers.basehttp import WSGIRequestHandler +orig_log_message = WSGIRequestHandler.log_message +def log_message_monkey(self, format, *args): + # Filter output for 200 or 304 responses. + if args[1] == '200' or args[1] == '304': + return + return orig_log_message(self, format, *args) + +WSGIRequestHandler.log_message = log_message_monkey + +from django.core.management.commands.runserver import Command