mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
logging: Use django.server to filter 200 and 304.
Previously, we were monkey patching the runserver command in zerver/management/commands/rundjango.py for this.
This commit is contained in:
@@ -149,7 +149,7 @@ pid_file.close()
|
|||||||
# Pass --nostatic because we configure static serving ourselves in
|
# Pass --nostatic because we configure static serving ourselves in
|
||||||
# zulip/urls.py.
|
# zulip/urls.py.
|
||||||
cmds = [['./tools/compile-handlebars-templates', 'forever'],
|
cmds = [['./tools/compile-handlebars-templates', 'forever'],
|
||||||
['./manage.py', 'rundjango'] +
|
['./manage.py', 'runserver'] +
|
||||||
manage_args + ['127.0.0.1:%d' % (django_port,)],
|
manage_args + ['127.0.0.1:%d' % (django_port,)],
|
||||||
['env', 'PYTHONUNBUFFERED=1', './manage.py', 'runtornado'] +
|
['env', 'PYTHONUNBUFFERED=1', './manage.py', 'runtornado'] +
|
||||||
manage_args + ['127.0.0.1:%d' % (tornado_port,)],
|
manage_args + ['127.0.0.1:%d' % (tornado_port,)],
|
||||||
|
|||||||
@@ -61,3 +61,13 @@ class RequireReallyDeployed(logging.Filter):
|
|||||||
# type: (logging.LogRecord) -> bool
|
# type: (logging.LogRecord) -> bool
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
return settings.PRODUCTION
|
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
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
# Wrapper around Django's runserver to allow filtering logs.
|
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from django.core.servers.basehttp import WSGIRequestHandler
|
|
||||||
orig_log_message = WSGIRequestHandler.log_message
|
|
||||||
def log_message_monkey(self, format, *args):
|
|
||||||
# type: (Any, str, *Any) -> None
|
|
||||||
# Filter output for 200 or 304 responses.
|
|
||||||
if args[1] == '200' or args[1] == '304':
|
|
||||||
return
|
|
||||||
orig_log_message(self, format, *args)
|
|
||||||
|
|
||||||
WSGIRequestHandler.log_message = log_message_monkey
|
|
||||||
|
|
||||||
from django.core.management.commands.runserver import Command
|
|
||||||
@@ -18,6 +18,7 @@ import sys
|
|||||||
import six.moves.configparser
|
import six.moves.configparser
|
||||||
|
|
||||||
from zerver.lib.db import TimeTrackingConnection
|
from zerver.lib.db import TimeTrackingConnection
|
||||||
|
import zerver.lib.logging_util
|
||||||
import six
|
import six
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@@ -969,6 +970,10 @@ LOGGING = {
|
|||||||
'require_really_deployed': {
|
'require_really_deployed': {
|
||||||
'()': 'zerver.lib.logging_util.RequireReallyDeployed',
|
'()': 'zerver.lib.logging_util.RequireReallyDeployed',
|
||||||
},
|
},
|
||||||
|
'skip_200_and_304': {
|
||||||
|
'()': 'django.utils.log.CallbackFilter',
|
||||||
|
'callback': zerver.lib.logging_util.skip_200_and_304,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'handlers': {
|
'handlers': {
|
||||||
'zulip_admins': {
|
'zulip_admins': {
|
||||||
@@ -1032,6 +1037,10 @@ LOGGING = {
|
|||||||
'handlers': ['file'],
|
'handlers': ['file'],
|
||||||
'propagate': False,
|
'propagate': False,
|
||||||
},
|
},
|
||||||
|
'django.server': {
|
||||||
|
'propagate': False,
|
||||||
|
'filters': ['skip_200_and_304'],
|
||||||
|
},
|
||||||
## Uncomment the following to get all database queries logged to the console
|
## Uncomment the following to get all database queries logged to the console
|
||||||
# 'django.db': {
|
# 'django.db': {
|
||||||
# 'handlers': ['console'],
|
# 'handlers': ['console'],
|
||||||
|
|||||||
Reference in New Issue
Block a user