开发者

grep-friendly logging of stack traces

I do a lot of grepping through logs generated by Java's Log4j and Python's logging module. Both create stack traces that include newline characters, causing the 开发者_Go百科log entry to span multiple lines. This makes things hard to find with grep and violates the conventional log file formatting rules (one entry per line).

If I find something interesting in the stack trace, I have to open entire the log file (which can be very large) and browse to the line grep found, then scroll up to find the start of the log entry. This feels kludgey.

Is there a better way to handle this? Perhaps removing newline characters from stack traces somehow?

Thanks for any suggestions!


If you have GNU grep you can use the -C (AKA --context) switch:

-C NUM, --context=NUM
Print NUM lines of output context. Places a line containing -- between contiguous groups of matches.

I'm not sure if -C is part of POSIX grep but it is worth a shot.


 grep 'your expressing and file name' | less

This will show you small stack first. Then enter to learn more.

You could also do 'head' or 'tail' of file name

  tail -1000 'filename'

This shows last(tail) 1000 lines from that file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜