Skip to content

Commit

Permalink
logging: Use django.server to filter 200 and 304.
Browse files Browse the repository at this point in the history
Previously, we were monkey patching the runserver command
in zerver/management/commands/rundjango.py for this.
  • Loading branch information
umairwaheed authored and timabbott committed Feb 10, 2017
1 parent 85fbdd6 commit ef0d2a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tools/run-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
# Pass --nostatic because we configure static serving ourselves in
# zulip/urls.py.
cmds = [['./tools/compile-handlebars-templates', 'forever'],
['./manage.py', 'rundjango'] +
['./manage.py', 'runserver'] +
manage_args + ['127.0.0.1:%d' % (django_port,)],
['env', 'PYTHONUNBUFFERED=1', './manage.py', 'runtornado'] +
manage_args + ['127.0.0.1:%d' % (tornado_port,)],
Expand Down
10 changes: 10 additions & 0 deletions zerver/lib/logging_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ def filter(self, record):
# type: (logging.LogRecord) -> bool
from django.conf import settings
return settings.PRODUCTION

def skip_200_and_304(record):
# type: (logging.LogRecord) -> bool
# Apparently, `status_code` is added by Django and is not an actual
# attribute of LogRecord; as a result, mypy throws an error if we
# access the `status_code` attribute directly.
if getattr(record, 'status_code') in [200, 304]:
return False

return True
16 changes: 0 additions & 16 deletions zerver/management/commands/rundjango.py

This file was deleted.

9 changes: 9 additions & 0 deletions zproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import six.moves.configparser

from zerver.lib.db import TimeTrackingConnection
import zerver.lib.logging_util
import six

########################################################################
Expand Down Expand Up @@ -969,6 +970,10 @@ def get_secret(key):
'require_really_deployed': {
'()': 'zerver.lib.logging_util.RequireReallyDeployed',
},
'skip_200_and_304': {
'()': 'django.utils.log.CallbackFilter',
'callback': zerver.lib.logging_util.skip_200_and_304,
},
},
'handlers': {
'zulip_admins': {
Expand Down Expand Up @@ -1032,6 +1037,10 @@ def get_secret(key):
'handlers': ['file'],
'propagate': False,
},
'django.server': {
'propagate': False,
'filters': ['skip_200_and_304'],
},
## Uncomment the following to get all database queries logged to the console
# 'django.db': {
# 'handlers': ['console'],
Expand Down

0 comments on commit ef0d2a4

Please sign in to comment.