-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathros-noetic-rosgraph.patch
96 lines (91 loc) · 3.96 KB
/
ros-noetic-rosgraph.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
diff --git a/src/rosgraph/roslogging.py b/src/rosgraph/roslogging.py
index 9ecc121893..0a94b2bed3 100644
--- a/src/rosgraph/roslogging.py
+++ b/src/rosgraph/roslogging.py
@@ -50,32 +50,58 @@ from rospkg.environment import ROS_LOG_DIR
class LoggingException(Exception): pass
class RospyLogger(logging.getLoggerClass()):
- def findCaller(self, *args, **kwargs):
+ # copied from python3.11/logging/__init__.py
+ # _srcfile is only used in conjunction with sys._getframe().
+ # Setting _srcfile to None will prevent findCaller() from being called. This
+ # way, you can avoid the overhead of fetching caller information.
+
+ # The following is based on warnings._is_internal_frame. It makes sure that
+ # frames of the import mechanism are skipped when logging at module level and
+ # using a stacklevel value greater than one.
+ @staticmethod
+ def _is_internal_frame(frame):
+ """Signal whether the frame is a CPython or logging module internal."""
+ filename = os.path.normcase(frame.f_code.co_filename)
+ return filename == logging._srcfile or (
+ "importlib" in filename and "_bootstrap" in filename
+ )
+
+
+ def findCaller(self, stack_info=False, stacklevel=1):
"""
Find the stack frame of the caller so that we can note the source
file name, line number, and function name with class name if possible.
"""
- file_name, lineno, func_name = super(RospyLogger, self).findCaller(*args, **kwargs)[:3]
- file_name = os.path.normcase(file_name)
-
- f = inspect.currentframe()
- if f is not None:
- f = f.f_back
- while hasattr(f, "f_code"):
- # Search for the right frame using the data already found by parent class.
- co = f.f_code
- filename = os.path.normcase(co.co_filename)
- if filename == file_name and f.f_lineno == lineno and co.co_name == func_name:
+
+
+ f = logging.currentframe()
+ #On some versions of IronPython, currentframe() returns None if
+ #IronPython isn't run with -X:Frames.
+ if f is None:
+ return "(unknown file)", 0, "(unknown function)", None
+ while stacklevel > 0:
+ next_f = f.f_back
+ if next_f is None:
+ ## We've got options here.
+ ## If we want to use the last (deepest) frame:
break
- if f.f_back:
- f = f.f_back
-
- # Jump up two more frames, as the logger methods have been double wrapped.
- if f is not None and f.f_back and f.f_code and f.f_code.co_name == '_base_logger':
- f = f.f_back
- if f.f_back:
- f = f.f_back
+ ## If we want to mimic the warnings module:
+ #return ("sys", 1, "(unknown function)", None)
+ ## If we want to be pedantic:
+ #raise ValueError("call stack is not deep enough")
+ f = next_f
+ if not RospyLogger._is_internal_frame(f):
+ stacklevel -= 1
co = f.f_code
+ sinfo = None
+ if stack_info:
+ with io.StringIO() as sio:
+ sio.write("Stack (most recent call last):\n")
+ traceback.print_stack(f, file=sio)
+ sinfo = sio.getvalue()
+ if sinfo[-1] == '\n':
+ sinfo = sinfo[:-1]
+
func_name = co.co_name
# Now extend the function name with class name, if available.
@@ -85,11 +111,7 @@ class RospyLogger(logging.getLoggerClass()):
except KeyError: # if the function is unbound, there is no self.
pass
- if sys.version_info > (3, 2):
- # Dummy last argument to match Python3 return type
- return co.co_filename, f.f_lineno, func_name, None
- else:
- return co.co_filename, f.f_lineno, func_name
+ return co.co_filename, f.f_lineno, func_name, sinfo
logging.setLoggerClass(RospyLogger)