Index: Lib/logging/__init__.py =================================================================== --- Lib/logging/__init__.py (revision 85007) +++ Lib/logging/__init__.py (working copy) @@ -58,17 +58,6 @@ except NameError: _unicode = False -# -# _srcfile is used when walking the stack to check when we've got the first -# caller stack frame. -# -if hasattr(sys, 'frozen'): #support for py2exe - _srcfile = "logging%s__init__%s" % (os.sep, __file__[-4:]) -elif __file__[-4:].lower() in ['.pyc', '.pyo']: - _srcfile = __file__[:-4] + '.py' -else: - _srcfile = __file__ -_srcfile = os.path.normcase(_srcfile) # next bit filched from 1.5.2's inspect.py def currentframe(): @@ -81,13 +70,6 @@ if hasattr(sys, '_getframe'): currentframe = lambda: sys._getframe(3) # done filching -# _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 # @@ -1199,20 +1181,14 @@ Find the stack frame of the caller so that we can note the source file name, line number and function name. """ + globs = globals() f = currentframe() - #On some versions of IronPython, currentframe() returns None if - #IronPython isn't run with -X:Frames. - if f is not None: - f = f.f_back rv = "(unknown file)", 0, "(unknown function)" - while hasattr(f, "f_code"): + while f is not None and f._globals is globs: + f = f.f_back + if f is not None: co = f.f_code - filename = os.path.normcase(co.co_filename) - if filename == _srcfile: - f = f.f_back - continue - rv = (filename, f.f_lineno, co.co_name) - break + rv = (os.co_filename, f.f_lineno, co.co_name) return rv def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None): @@ -1233,16 +1209,7 @@ Low-level logging routine which creates a LogRecord and then calls all the handlers of this logger to handle the record. """ - if _srcfile: - #IronPython doesn't track Python frames, so findCaller throws an - #exception on some versions of IronPython. We trap it here so that - #IronPython can use logging. - try: - fn, lno, func = self.findCaller() - except ValueError: - fn, lno, func = "(unknown file)", 0, "(unknown function)" - else: - fn, lno, func = "(unknown file)", 0, "(unknown function)" + fn, lno, func = self.findCaller() if exc_info: if not isinstance(exc_info, tuple): exc_info = sys.exc_info()