突出蟒蛇堆栈跟踪 [英] Highlighting python stack traces

查看:197
本文介绍了突出蟒蛇堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我时间后,工作相当复杂的项目,我一定要缩小看着堆栈跟踪的问题。他们碰巧是很长,涉及到我的code,标准库code和第三方库美元,同时C $℃。多数时候,真正的问题是我的code和堆栈跟踪定位瞬间实在是有点困难的眼睛。在我的code我的意思是code这是当前工作目录下。

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:

使用supercat由丹尼斯·威廉姆森认为,中间结果如下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:


  1. 我看不到任何输出nosetests完成之前。即我没有看到进展。

  2. 我必须写2>&安培;一遍遍1

UPD 2:

问这个问题,我不得不主要 nosetests 的初衷。我只是找到很好的解决方案: rednose 的鼻子插件。它强调的是局部加做许多更加得心应手可读性的东西路径。

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流,冲洗,管道,重定向的问题。因此,作为一个答案来的问的问题的我接受建议supercat一个答案。

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.

推荐答案

看看 Supercat (SPC)。它ANSI和HTML突出,可配置为您的特定输出。它配备了一种在C和Python源$ C ​​$ C文件一些配置文件,如文件和日志文件,更新日志,比较和其他。

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.

根据戴维Kirby的建议为VIM,这样做类似的事情:

Based on Dave Kirby's suggestion for vim, this does something similar:

less -p regex file_name

或者

some_command | less -p regex

这篇关于突出蟒蛇堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆