37
37
__author__ = "Vinay Sajip <[email protected] >"
38
38
__status__ = "beta"
39
39
__version__ = "0.4.9.6"
40
- __date__ = "20 October 2004 "
40
+ __date__ = "03 February 2005 "
41
41
42
42
#---------------------------------------------------------------------------
43
43
# Miscellaneous module data
44
44
#---------------------------------------------------------------------------
45
45
46
46
#
47
- #_srcfile is used when walking the stack to check when we've got the first
47
+ # _srcfile is used when walking the stack to check when we've got the first
48
48
# caller stack frame.
49
49
#
50
50
if string .lower (__file__ [- 4 :]) in ['.pyc' , '.pyo' ]:
53
53
_srcfile = __file__
54
54
_srcfile = os .path .normcase (_srcfile )
55
55
56
+ # next bit filched from 1.5.2's inspect.py
57
+ def currentframe ():
58
+ """Return the frame object for the caller's stack frame."""
59
+ try :
60
+ raise 'catch me'
61
+ except :
62
+ return sys .exc_traceback .tb_frame .f_back
63
+
64
+ if hasattr (sys , '_getframe' ): currentframe = sys ._getframe
65
+ # done filching
66
+
56
67
# _srcfile is only used in conjunction with sys._getframe().
57
68
# To provide compatibility with older versions of Python, set _srcfile
58
69
# to None if _getframe() is not available; this value will prevent
59
70
# findCaller() from being called.
60
- if not hasattr (sys , "_getframe" ):
61
- _srcfile = None
71
+ # if not hasattr(sys, "_getframe"):
72
+ # _srcfile = None
62
73
63
74
#
64
75
#_startTime is used as the base when calculating the relative time of events
@@ -1005,16 +1016,16 @@ def log(self, level, msg, *args, **kwargs):
1005
1016
def findCaller (self ):
1006
1017
"""
1007
1018
Find the stack frame of the caller so that we can note the source
1008
- file name and line number.
1019
+ file name, line number and function name .
1009
1020
"""
1010
- f = sys . _getframe ( 1 )
1021
+ f = currentframe (). f_back
1011
1022
while 1 :
1012
1023
co = f .f_code
1013
1024
filename = os .path .normcase (co .co_filename )
1014
1025
if filename == _srcfile :
1015
1026
f = f .f_back
1016
1027
continue
1017
- return filename , f .f_lineno
1028
+ return filename , f .f_lineno , co . co_name
1018
1029
1019
1030
def makeRecord (self , name , level , fn , lno , msg , args , exc_info ):
1020
1031
"""
@@ -1029,9 +1040,9 @@ def _log(self, level, msg, args, exc_info=None):
1029
1040
all the handlers of this logger to handle the record.
1030
1041
"""
1031
1042
if _srcfile :
1032
- fn , lno = self .findCaller ()
1043
+ fn , lno , func = self .findCaller ()
1033
1044
else :
1034
- fn , lno = "< unknown file> " , 0
1045
+ fn , lno , func = "( unknown file) " , 0 , "(unknown function)"
1035
1046
if exc_info :
1036
1047
if type (exc_info ) != types .TupleType :
1037
1048
exc_info = sys .exc_info ()
0 commit comments