def logFunctionAndArgs():
frame = inspect.getouterframes(inspect.currentframe())[1][0]
args, _, _, values = inspect.getargvalues(frame)
frameinfo = inspect.getframeinfo(frame)
functionName=inspect.getframeinfo(frame)[2]
output = ""
for arg in args[1:]: #[1:] skip the first argument 'self'
value = values[arg]
if isinstance(value, str):
#add apostrophes for string values
value = "\'"+value+"\'"
elif isinstance(value, int):
value = ''.join('%02X' % value)
else:
newValue = ""
for i in value:
if isinstance(i, int):
newValue += '%02X' % i
else:
newValue += str(i)
value = newValue
output += arg + '=' + value
if arg != args[-1]:
#add comma if not the last element
output +=','
#do not print "\n' as a new line
output = output.replace("\n","\\n")
logging.info("--> "+functionName+'('+output+')')
评论列表
文章目录