Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 57d2fc5

Browse files
committed
breadcrumbs: Check logging._srcfile in _wrap_logging_method
The _srcfile attribute of the logging module may be None if the interpreter doesn't support frame introspection (see comment in logging/__init__.py).
1 parent 1e52542 commit 57d2fc5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

raven/breadcrumbs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22

3+
import os
34
import time
45
import logging
56
from types import FunctionType
@@ -154,6 +155,12 @@ def _wrap_logging_method(meth, level=None):
154155

155156
code = get_code(func)
156157

158+
logging_srcfile = logging._srcfile
159+
if logging_srcfile is None:
160+
logging_srcfile = os.path.normpath(
161+
logging.currentframe.__code__.co_filename
162+
)
163+
157164
# This requires a bit of explanation why we're doing this. Due to how
158165
# logging itself works we need to pretend that the method actually was
159166
# created within the logging module. There are a few ways to detect
@@ -183,7 +190,7 @@ def %(name)s(self, %(args)s, *args, **kwargs):
183190
'args': ', '.join(args),
184191
'fwd': fwd,
185192
'level': level,
186-
}, logging._srcfile, 'exec'), logging.__dict__, ns)
193+
}, logging_srcfile, 'exec'), logging.__dict__, ns)
187194

188195
new_func = ns['factory'](meth, _record_log_breadcrumb)
189196
new_func.__doc__ = func.__doc__

0 commit comments

Comments
 (0)