0001-utils-include-exception-logging-in-log_http_request-.patch
passerelle/utils/__init__.py | ||
---|---|---|
188 | 188 |
log_function = logger.info |
189 | 189 |
message = '' |
190 | 190 |
extra = extra or {} |
191 |
kwargs = {} |
|
191 | 192 | |
192 | 193 |
if request is not None: |
193 | 194 |
message = '%s %s' % (request.method, request.url) |
... | ... | |
222 | 223 |
message = repr(exception) |
223 | 224 |
extra['response_exception'] = repr(exception) |
224 | 225 |
log_function = logger.error |
226 |
kwargs['exc_info'] = exception |
|
225 | 227 | |
226 | 228 |
# allow resources to disable any error log at requests level |
227 | 229 |
if not error_log: |
228 | 230 |
log_function = logger.info |
229 |
log_function(message, extra=extra) |
|
231 |
log_function(message, extra=extra, **kwargs)
|
|
230 | 232 | |
231 | 233 | |
232 | 234 |
# Wrapper around requests.Session |
tests/test_proxylogger.py | ||
---|---|---|
5 | 5 |
import logging |
6 | 6 | |
7 | 7 |
import pytest |
8 |
import requests |
|
8 | 9 |
import utils |
9 | 10 |
from django.core.exceptions import ValidationError |
10 | 11 |
from django.utils.log import AdminEmailHandler |
... | ... | |
381 | 382 |
assert ResourceLog.objects.all()[1].extra.get('response_content') == '\'{"service_reply_var": "33\'' |
382 | 383 |
else: |
383 | 384 |
assert ResourceLog.objects.all()[1].extra.get('response_content') == 'b\'{"service_reply_var": "33\'' |
385 | ||
386 | ||
387 |
def test_proxy_logger_email_traceback(app, db, email_handler, settings, mailoutbox, connector, monkeypatch): |
|
388 |
settings.ADMINS = [('admin', 'admin@example.net')] |
|
389 |
endpoint_url = utils.generic_endpoint_url('feeds', 'json', slug=connector.slug) |
|
390 | ||
391 |
@endpoint() |
|
392 |
def json(self, request): |
|
393 |
raise requests.ConnectionError('timeout') |
|
394 | ||
395 |
monkeypatch.setattr(Feed, 'json', json) |
|
396 |
resp = app.get(endpoint_url, status=500) |
|
397 |
assert any('traceback' in mail.body.lower() for mail in mailoutbox) |
|
384 |
- |