summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2016-05-14 01:37:41 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2016-05-14 01:37:41 +0200
commita4c7f0c36b6ba17f736f76e356102fe214348210 (patch)
treee2a113436bed06e0393aca733af9655d2dd1cc64
parentc3e3e4dcbb1459e8b93be3bddca4cbcbdb971362 (diff)
downloadraven-a4c7f0c36b6ba17f736f76e356102fe214348210.tar.gz
More resilient log reporting.
-rw-r--r--raven/breadcrumbs.py14
-rw-r--r--tests/breadcrumbs/tests.py12
2 files changed, 23 insertions, 3 deletions
diff --git a/raven/breadcrumbs.py b/raven/breadcrumbs.py
index a0c91a6..2ef13c5 100644
--- a/raven/breadcrumbs.py
+++ b/raven/breadcrumbs.py
@@ -78,9 +78,17 @@ def _record_log_breadcrumb(logger, level, msg, *args, **kwargs):
return
def processor(data):
- formatted_msg = text_type(msg)
- if args:
- formatted_msg = msg % args
+ formatted_msg = msg
+
+ # If people log bad things, this can happen. Then just don't do
+ # anything.
+ try:
+ formatted_msg = text_type(msg)
+ if args:
+ formatted_msg = msg % args
+ except Exception:
+ pass
+
# We do not want to include exc_info as argument because it often
# lies (set to a constant value like 1 or True) or even if it's a
# tuple it will not be particularly useful for us as we cannot
diff --git a/tests/breadcrumbs/tests.py b/tests/breadcrumbs/tests.py
index ab424d8..00fd463 100644
--- a/tests/breadcrumbs/tests.py
+++ b/tests/breadcrumbs/tests.py
@@ -56,3 +56,15 @@ class BreadcrumbTestCase(TestCase):
assert int(items[3]) == lineno
assert items[4] == 'INFO'
assert items[5] == 'Hello World!'
+
+ def test_broken_logging(self):
+ client = Client('http://foo:bar@example.com/0')
+ with client.context:
+ log = logging.getLogger('whatever.foo')
+ log.info('This is a message with %s. %s!', 42)
+ crumbs = client.context.breadcrumbs.get_buffer()
+
+ assert len(crumbs) == 1
+ assert crumbs[0]['type'] == 'default'
+ assert crumbs[0]['category'] == 'whatever.foo'
+ assert crumbs[0]['message'] == 'This is a message with %s. %s!'