misc: log DisallowedHost as warnings (#42824)
This commit is contained in:
parent
6beaab79fe
commit
d1636eeece
|
@ -71,6 +71,10 @@ LOGGING = {
|
|||
'debug_log': {
|
||||
'()': 'hobo.logger.DebugLogFilter',
|
||||
},
|
||||
'clamp_to_warning': {
|
||||
'()': 'hobo.logger.ClampLogLevel',
|
||||
'level': 'WARNING',
|
||||
}
|
||||
},
|
||||
'formatters': {
|
||||
'syslog': {
|
||||
|
@ -146,13 +150,14 @@ LOGGING = {
|
|||
'level': 'NOTSET',
|
||||
'propagate': True,
|
||||
},
|
||||
'django.core.exceptions.SuspiciousFileOperation': {
|
||||
'handlers': ['null'],
|
||||
'propagate': False,
|
||||
'django.security.SuspiciousFileOperation': {
|
||||
'filters': ['clamp_to_warning'],
|
||||
},
|
||||
'django.security.DisallowedRedirect': {
|
||||
'handlers': ['null'],
|
||||
'propagate': False,
|
||||
'filters': ['clamp_to_warning'],
|
||||
},
|
||||
'django.core.exceptions.DisallowedHost': {
|
||||
'filters': ['clamp_to_warning'],
|
||||
},
|
||||
'django.template': {
|
||||
# too much logs on DEBUG level
|
||||
|
|
|
@ -217,3 +217,16 @@ class DebugLog(object):
|
|||
return
|
||||
for record in cls(debug_log_path)._parse(cursor=cursor):
|
||||
yield record
|
||||
|
||||
|
||||
class ClampLogLevel(logging.Filter):
|
||||
def __init__(self, level):
|
||||
self.levelname = level.upper()
|
||||
self.levelno = getattr(logging, self.levelname)
|
||||
super(ClampLogLevel, self).__init__()
|
||||
|
||||
def filter(self, record):
|
||||
if record.levelno > self.levelno:
|
||||
record.levelno = self.levelno
|
||||
record.levelname = self.levelname
|
||||
return super(ClampLogLevel, self).filter(record)
|
||||
|
|
|
@ -24,7 +24,7 @@ import pytest
|
|||
|
||||
from tenant_schemas.utils import tenant_context
|
||||
|
||||
from hobo.logger import DebugLog
|
||||
from hobo.logger import DebugLog, ClampLogLevel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -105,3 +105,10 @@ def test_debug_log(tenants, settings, app, rf, debug_log, freezer):
|
|||
lines2 = list(DebugLog.lines(cursor=lines[0]['cursor']))
|
||||
assert len(lines2) == 1
|
||||
assert lines[1] == lines2[0]
|
||||
|
||||
|
||||
def test_clamp_log_level(caplog):
|
||||
logger = logging.getLogger('django.security.SuspiciousFileOperation')
|
||||
logger.addFilter(ClampLogLevel(level='WARNING'))
|
||||
logger.error('test')
|
||||
assert caplog.records[-1].levelname == 'WARNING'
|
||||
|
|
Loading…
Reference in New Issue