summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2014-06-12 22:36:33 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2014-06-12 22:36:33 (GMT)
commit194bcaf4dc4a7cfcfd33ff90dd22178df28f78d7 (patch)
tree8bd074e8048cb6c6f68c34f5f14f7d2d2ce350b3 /Lib/logging
parent307bccc6ff6670c58f4c20421a29071ff710e6a3 (diff)
downloadcpython-194bcaf4dc4a7cfcfd33ff90dd22178df28f78d7.zip
cpython-194bcaf4dc4a7cfcfd33ff90dd22178df28f78d7.tar.gz
cpython-194bcaf4dc4a7cfcfd33ff90dd22178df28f78d7.tar.bz2
Issue #21709: Improved implementation to cover the frozen module case.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py62
1 files changed, 34 insertions, 28 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 21ab627..a61c2b0 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -52,34 +52,6 @@ __date__ = "07 February 2010"
#---------------------------------------------------------------------------
#
-# _srcfile is used when walking the stack to check when we've got the first
-# caller stack frame.
-#
-if hasattr(sys, 'frozen'):
- _srcfile = os.path.join('logging', '__init__.py')
-else:
- _srcfile = __file__
-_srcfile = os.path.normcase(_srcfile)
-
-
-if hasattr(sys, '_getframe'):
- currentframe = lambda: sys._getframe(3)
-else: #pragma: no cover
- def currentframe():
- """Return the frame object for the caller's stack frame."""
- try:
- raise Exception
- except Exception:
- return sys.exc_info()[2].tb_frame.f_back
-
-# _srcfile is only used in conjunction with sys._getframe().
-# To provide compatibility with older versions of Python, set _srcfile
-# to None if _getframe() is not available; this value will prevent
-# findCaller() from being called.
-#if not hasattr(sys, "_getframe"):
-# _srcfile = None
-
-#
#_startTime is used as the base when calculating the relative time of events
#
_startTime = time.time()
@@ -172,6 +144,40 @@ def addLevelName(level, levelName):
finally:
_releaseLock()
+if hasattr(sys, '_getframe'):
+ currentframe = lambda: sys._getframe(3)
+else: #pragma: no cover
+ def currentframe():
+ """Return the frame object for the caller's stack frame."""
+ try:
+ raise Exception
+ except Exception:
+ return sys.exc_info()[2].tb_frame.f_back
+
+#
+# _srcfile is used when walking the stack to check when we've got the first
+# caller stack frame, by skipping frames whose filename is that of this
+# module's source. It therefore should contain the filename of this module's
+# source file.
+#
+# Ordinarily we would use __file__ for this, but frozen modules don't always
+# have __file__ set, for some reason (see Issue #21736). Thus, we get the
+# filename from a handy code object from a function defined in this module.
+# (There's no particular reason for picking addLevelName.)
+#
+
+_srcfile = os.path.normcase(addLevelName.__code__.co_filename)
+
+# _srcfile is only used in conjunction with sys._getframe().
+# To provide compatibility with older versions of Python, set _srcfile
+# to None if _getframe() is not available; this value will prevent
+# findCaller() from being called. You can also do this if you want to avoid
+# the overhead of fetching caller information, even when _getframe() is
+# available.
+#if not hasattr(sys, '_getframe'):
+# _srcfile = None
+
+
def _checkLevel(level):
if isinstance(level, int):
rv = level