From 3fa39604ffc1bbf7bb40dc9ab3773a940f1a5491 Mon Sep 17 00:00:00 2001 From: Kartik Mohta Date: Thu, 3 Aug 2017 21:08:02 -0400 Subject: [PATCH] Make RospyLogger.findCaller compatible with Python3 The findCaller function in Python3 logging module takes 2 arguments (including self) compared to only self in Python2. --- tools/rosgraph/src/rosgraph/roslogging.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/roslogging.py b/tools/rosgraph/src/rosgraph/roslogging.py index 48e5024c34..3bfcfcf1cc 100644 --- a/tools/rosgraph/src/rosgraph/roslogging.py +++ b/tools/rosgraph/src/rosgraph/roslogging.py @@ -49,12 +49,12 @@ class LoggingException(Exception): pass class RospyLogger(logging.getLoggerClass()): - def findCaller(self): + def findCaller(self, dummy=False): # Dummy second arg to match Python3 function declaration """ 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() + file_name, lineno, func_name = super(RospyLogger, self).findCaller()[:3] f = inspect.currentframe() if f is not None: @@ -74,7 +74,10 @@ def findCaller(self): except KeyError: # if the function is unbound, there is no self. pass break - return file_name, lineno, func_name + if sys.version_info > (3, 2): + return file_name, lineno, func_name, None # Dummy last argument to match Python3 return type + else: + return file_name, lineno, func_name logging.setLoggerClass(RospyLogger)