0001-logging-shorten-http-403-message-displayed-by-syslog.patch
debian/debian_config_common.py | ||
---|---|---|
80 | 80 |
}, |
81 | 81 |
'formatters': { |
82 | 82 |
'syslog': { |
83 |
'()': 'hobo.utils.CustomSyslogFormatter', |
|
83 | 84 |
'format': '%(application)s %(levelname)s %(tenant)s %(ip)s %(user)s %(request_id)s' |
84 | 85 |
' %(message)s', |
85 | 86 |
}, |
hobo/utils.py | ||
---|---|---|
1 |
import logging |
|
2 | ||
1 | 3 |
from django.conf import settings |
2 | 4 |
from django.template import Context, Template, TemplateSyntaxError, VariableDoesNotExist |
3 | 5 |
from mellon.adapters import DefaultAdapter |
... | ... | |
36 | 38 |
raise TemplateError(e.msg, e.params) |
37 | 39 |
except TemplateSyntaxError: |
38 | 40 |
raise TemplateError('syntax error') |
41 | ||
42 | ||
43 |
class CustomSyslogFormatter(logging.Formatter): |
|
44 |
def format(self, record): |
|
45 |
status_code = getattr(record, 'status_code', None) |
|
46 | ||
47 |
if status_code == 403: # shorten the message on permission denied errors |
|
48 |
record.msg = record.msg.split('Traceback')[0] |
|
49 | ||
50 |
return super().format(record) |
|
39 |
- |