问题描述
我正在开展相当复杂的项目,随着时间的推移,我必须缩小查询堆栈跟踪的问题。他们碰巧很长,同时涉及到我的代码,标准库代码和第三方库代码。大多数时候,真正的问题在于我的代码,并且立即将其定位在堆栈跟踪中,对于眼睛来说有点困难。在我的代码下,我的意思是当前工作目录下的代码。
I'm working on quite complex project and time after time I have to narrow down problems looking at stack traces. They happen to be very long and involve "my" code, standard library code and 3rd party libraries code at same time. Most of time the real problem is in "my" code and locating it instantly in a stack trace is a bit hard for eyes. Under "my" code I mean the code that is under current working directory.
所以我意识到我想要一些将着色堆栈跟踪并突出显示我的行的东西。将与。
So I realized that I want something that will colorize stack traces and highlight lines that are mine. Compare original to highlighted.
我可以写一个python脚本我可以这样使用:
I could write a python script that I could use this way:
nosetests | colorize_stack_trace.py
但是我相信使用Linux工具集有更快更优雅的方法。任何想法?
But I believe there is a quicker and more elegant way to do this using Linux toolset. Any ideas?
UPD:
使用Dennis Williamson建议的超级猫中间结果是跟随bash函数:
Using supercat suggested by Dennis Williamson, the intermediate result is following bash function:
pyst() {
rc=/tmp/spcrc;
echo '#################### ### # # # ########################################' > $rc;
echo ' blk 0 r ^(.*)$' >> $rc;
echo ' mag b 0 r ^\s*File "'`pwd`'/(.*)"' >> $rc;
spc -c $rc;
}
现在我可以做:
nosetests 2>&1 | pyst
不太优雅,但在某种程度上有效。有两个问题:
Not too elegant, but works at some degree. There are two problems left:
- 在nosetests完成之前,我看不到任何输出。即我没有看到进度。
- 我必须一遍又一遍地写2& 1。
UPD 2:
提出这个问题我主要是 nosetests
记住。我刚刚找到了很好的解决方案:鼻子插件。它突出了本地的路径,并提供更多便利的可读性。
Asking this question I had mainly nosetests
in mind. And I just found great solution: rednose nose plugin. It highlights paths that are local plus do many more handy readability things.
回到原始问题:我用supercat注意到的问题与它完全没有关系, Unix shell流,冲洗,管道,重定向的问题。所以作为问题的答案我接受一个建议超级的答案。
Returning to original question: problems that I noted with supercat don't relate to it completely but its a problem of Unix shell streaming, flushing, piping, redirecting. So as as an answer to the question asked I accept an answer that suggests supercat.
推荐答案
看看(spc)。它同时执行ANSI和HTML突出显示,可以为您的特定输出进行配置。它包含一些C和Python中的源代码文件的配置文件,例如日志文件,更改日志,差异等。
Take a look at Supercat (spc). It does both ANSI and HTML highlighting and can be configured for your particular output. It comes with some configuration files for source code files in C and Python, for example and log files, Changelogs, diffs and others.
根据 Dave Kirby的对vim的建议,这样做类似:
Based on Dave Kirby's suggestion for vim, this does something similar:
less -p regex file_name
或
some_command | less -p regex
这篇关于突出显示python堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!