use cef as a formatter (bug 628417)
This commit is contained in:
Родитель
5cccbd7bff
Коммит
16198f0a59
|
@ -350,11 +350,15 @@ def cspreport(request):
|
|||
"""Accept CSP reports and log them."""
|
||||
try:
|
||||
v = json.loads(request.raw_post_data)['csp-report']
|
||||
msg = ("CSP Violation Report: (Request: %s) (Blocked: %s) (Rule: %s)"
|
||||
% (v['request'], v['blocked-uri'], v['violated-directive']))
|
||||
csp_log.warning(msg)
|
||||
# Having the request headers was putting us close to a maxlen limit.
|
||||
if 'request-headers' in v:
|
||||
del v['request-headers']
|
||||
# This requires you to use the cef.formatter to get something nice out.
|
||||
csp_log.warning('Violation', dict(environ=request.META,
|
||||
product='addons',
|
||||
username=request.user,
|
||||
data=v))
|
||||
except Exception:
|
||||
csp_log.debug("Got a malformed violation report. Ignoring...")
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
return HttpResponse()
|
||||
|
|
|
@ -6,6 +6,8 @@ from django.conf import settings
|
|||
import commonware.log
|
||||
import dictconfig
|
||||
|
||||
from cef import cef
|
||||
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
|
||||
|
@ -37,6 +39,11 @@ cfg = {
|
|||
'format': '%s: [%%(REMOTE_ADDR)s] %s' % (settings.SYSLOG_TAG2,
|
||||
base_fmt),
|
||||
},
|
||||
'csp': {
|
||||
'()': cef.SysLogFormatter,
|
||||
'datefmt': '%H:%M:%s',
|
||||
'format': '%s: %s' % (settings.SYSLOG_CSP, base_fmt),
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
|
@ -53,6 +60,11 @@ cfg = {
|
|||
'facility': logging.handlers.SysLogHandler.LOG_LOCAL7,
|
||||
'formatter': 'prod2',
|
||||
},
|
||||
'syslog_csp': {
|
||||
'()': logging.handlers.SysLogHandler,
|
||||
'facility': logging.handlers.SysLogHandler.LOG_LOCAL7,
|
||||
'formatter': 'csp',
|
||||
},
|
||||
'null': {
|
||||
'()': NullHandler,
|
||||
},
|
||||
|
@ -78,8 +90,10 @@ for key, value in settings.LOGGING.items():
|
|||
|
||||
USE_SYSLOG = settings.HAS_SYSLOG and not settings.DEBUG
|
||||
|
||||
|
||||
if USE_SYSLOG:
|
||||
cfg['loggers']['z.timer'] = {'handlers': ['syslog2']}
|
||||
cfg['loggers']['z.csp'] = {'handlers': ['syslog_csp'], 'level':'WARNING'}
|
||||
|
||||
# Set the level and handlers for all loggers.
|
||||
for logger in cfg['loggers'].values() + [cfg['root']]:
|
||||
|
|
|
@ -17,6 +17,7 @@ django-celery==2.0.2
|
|||
importlib==1.0.2
|
||||
mongoengine==0.3
|
||||
django-uuidfield==0.1
|
||||
cef==0.2
|
||||
|
||||
-e git://github.com/jbalogh/django-multidb-router.git#egg=django-multidb-router
|
||||
-e git://github.com/jbalogh/django-cache-machine.git@0ca435683#egg=django-cache-machine
|
||||
|
|
|
@ -666,6 +666,7 @@ LOG_LEVEL = logging.DEBUG
|
|||
HAS_SYSLOG = True # syslog is used if HAS_SYSLOG and NOT DEBUG.
|
||||
SYSLOG_TAG = "http_app_addons"
|
||||
SYSLOG_TAG2 = "http_app_addons2"
|
||||
SYSLOG_CSP = "http_app_addons_csp"
|
||||
# See PEP 391 and log_settings.py for formatting help. Each section of
|
||||
# LOGGING will get merged into the corresponding section of
|
||||
# log_settings.py. Handlers and log levels are set up automatically based
|
||||
|
|
Загрузка…
Ссылка в новой задаче