寻找一种通过单击控制台中的某些输出行来跳至代码行的方法(类似于Eclipse功能)我当前的输出看起来像这样:
C:\anaconda3\python.exe C:/test/TestUnit.py
2018-06-01 10:43:26,610 TestUnit.py <module>() 8 INFO TestUnit started, checking input params ...
2018-06-01 10:43:26,610 TestUnit.py <module>() 27 INFO Provided video file: [D:\input\video.mp4]
2018-06-01 10:43:26,613 Video.py getFrames() 4 INFO Extracting frames from input video D:\input\video.mp4
是否可以单击getFrames()并使IDE跳转到文件get.Frames()中的video.py =>相关代码行?
看起来像这样:
class Video(object):
def getFrames(video,log):
log.info("Extracting frames from input video " + video) <<====== jump to this
提前感谢!
为每个有相同问题的人回答这个旧问题。
日志输出需要包括此部分:
File "/path/to/file.py", line 140
使用Python的日志记录模块,您可以实现此目的
format="File \"%(pathname)s\", line %(lineno)d"
这是日志记录配置的完整示例
logging.basicConfig(level=10, format="[%(asctime)s] %(levelname)s [File \"%(pathname)s\", line %(lineno)d] %(message)s", datefmt="%H:%M:%S", stream=sys.stdout)