import sys
import datetime
def print_debug_info(o):
try:
raise Exception
except :
f = sys.exc_info()[2].tb_frame.f_back
print('%s %s %d %s ' % (str(datetime.datetime.now()), os.path.basename(f.f_code.co_filename), f.f_lineno, f.f_code.co_name), end='')
print(o)
print_debug_info("content")
输出结果:
2019-07-06 19:44:03.021493 D:/XXXXX/1.py 15 <module> content