diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2016-05-09 20:48:52 +0200 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2016-05-09 21:03:16 +0200 |
commit | a50ca80be1ca931a49fb27343e8fbb2fa52e2113 (patch) | |
tree | 9e7fecfa291a78e4441d67a7a57f553f12cd9736 | |
parent | bf91eb9f169c90c0771c1410c7d694ed818f0472 (diff) | |
download | raven-a50ca80be1ca931a49fb27343e8fbb2fa52e2113.tar.gz |
Corrected an issue where logging locations were reported incorrectly.
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | raven/breadcrumbs.py | 2 | ||||
-rw-r--r-- | tests/breadcrumbs/tests.py | 29 |
3 files changed, 33 insertions, 1 deletions
@@ -5,6 +5,9 @@ Version 5.16.0 * log the entire logger name as category. * added a `enable_breadcrumbs` flag to the client to allow the enabling or disabling of breadcrumbs quickly. +* corrected an issue where python interpreters with bytecode writing enabled + would report incorrect logging locations when breadcrumb patching for + logging was enabled. Version 5.15.0 -------------- diff --git a/raven/breadcrumbs.py b/raven/breadcrumbs.py index 389ce26..a0c91a6 100644 --- a/raven/breadcrumbs.py +++ b/raven/breadcrumbs.py @@ -143,7 +143,7 @@ def _wrap_logging_method(meth, level=None): 'args': ', '.join(args), 'fwd': fwd, 'level': level, - }, logging.__file__, 'exec'), logging.__dict__, ns) + }, logging._srcfile, 'exec'), logging.__dict__, ns) new_func = ns['factory'](meth, _record_log_breadcrumb) new_func.__doc__ = func.__doc__ diff --git a/tests/breadcrumbs/tests.py b/tests/breadcrumbs/tests.py index a49db93..85f6192 100644 --- a/tests/breadcrumbs/tests.py +++ b/tests/breadcrumbs/tests.py @@ -1,3 +1,4 @@ +import sys import logging from raven.utils.testutils import TestCase @@ -5,6 +6,11 @@ from raven.utils.testutils import TestCase from raven.base import Client from raven.breadcrumbs import record_breadcrumb +try: + from cStringIO import StringIO as BytesIO +except ImportError: + from io import BytesIO + class BreadcrumbTestCase(TestCase): @@ -30,3 +36,26 @@ class BreadcrumbTestCase(TestCase): assert crumbs[0]['category'] == 'whatever.foo' assert crumbs[0]['data'] == {'blah': 'baz'} assert crumbs[0]['message'] == 'This is a message with foo!' + + def test_log_location(self): + out = BytesIO() + logger = logging.getLogger(__name__) + logger.setLevel(logging.DEBUG) + handler = logging.StreamHandler(out) + handler.setFormatter(logging.Formatter( + '%(name)s|%(filename)s|%(funcName)s|%(lineno)d|' + '%(levelname)s|%(message)s')) + logger.addHandler(handler) + + client = Client('http://foo:bar@example.com/0') + with client.context: + logger.info('Hello World!') + lineno = sys._getframe().f_lineno - 1 + + items = out.getvalue().strip().decode('utf-8').split('|') + assert items[0] == b'tests.breadcrumbs.tests' + assert items[1].rstrip(b'co') == b'tests.py' + assert items[2] == b'test_log_location' + assert int(items[3]) == lineno + assert items[4] == b'INFO' + assert items[5] == b'Hello World!' |