我有多线程应用程序的日志文件。每行都有众所周知的格式(例如,第三个字段是线程 ID)。其中一个字段是线程 ID。我希望我没有尝试重新发明轮子:)
无论如何,为了轻松阅读文件,我想到了两个可以提供帮助的选项:
-
突出显示与当前行具有相同线程 id 的所有行。
-
如果按下某个按键,则折叠所有具有其他线程 id 的行,再次按下该按键将展开该行。
欢迎提供这两个项目的骨架。
I have log file of multi threaded application. Each line has a well know format (e.g. 3rd field is thread id). while one of fields is thread id. I hope that I'm not trying to reinvent the wheel :)
Any way, to easy reading of the file, I thought of two options that could help:
-
Highlight all lines with the same thread id as current line.
-
If some keystroke is pressed, all lines with other thread id are folded, pressing again the keystroke unfold the lines.
A skeleton for both items is welcomed.
发布评论
评论(2)
按模式突出显示
这是一个用于突出显示(另一个用于清除)包含给定模式的所有行的函数,并在模式本身上强调突出显示。 “最后搜索”寄存器
@/
也设置为请求的模式,因此n
/N
在正常模式下向前/向后跳转匹配线。l
(相当于大多数安装中的\l
)是突出显示包含WORD
在光标下。按模式折叠
有关基于模式折叠的示例,请查看 Show-Hide Vim插件。它提供了两个命令,
SHOW
和HIDE
,以及一些快捷方式映射。例如,:SHOW thread=1234
将折叠除包含thread=1234
的行之外的所有行,而正常模式下的zs
将显示包含以下内容的行:光标下的单词
。 [您可能需要创建备用地图,例如zS
,以使用
而不是
.]构建模式
如果既不是 提取足够独特的过滤模式(或避免将光标移动到正确的字段),创建另一个类似下面的函数并从映射中调用它。
也不是Highlighting by pattern
Here is a function to highlight (and another to clear) all lines that contain a given pattern, with an accent highlight on the pattern itself. The "last search" register
@/
is also set to the requested pattern son
/N
, in normal mode, jumps forwards/backwards through matching lines.<Leader>l
(equivalent to\l
on most installs) is a shortcut to highlight lines that contain theWORD
under your cursor.Folding by pattern
For an example of folding based on patterns, check out the Show-Hide Vim plug-in. It provides two commands,
SHOW
andHIDE
, and a few shortcut maps. For example,:SHOW thread=1234
will fold all lines except those that containthread=1234
, whilezs
in normal mode will show lines containing theword
under your cursor. [You may want to create an alternate map, such aszS
, to use<cWORD>
instead of<cword>
.]Building patterns
If neither
<cword>
nor<cWORD>
extract a sufficiently unique filter pattern (or to avoid moving the cursor to the proper field), create another function like the one below and call it from a map.您基本上正在寻找的是在日志文件之上构建的外部机制。
Chainsaw 正是针对基于 log4j 的日志执行此操作:
http://logging.apache.org/chainsaw/index.html
不确定是什么你的日志记录应用程序,但你可能应该看看那个方向。
What you are basically looking for is an external mechanisem to be built on top of your log file.
Chainsaw is doing exactly that for log4j based logs:
http://logging.apache.org/chainsaw/index.html
Not sure what is your logging application, but you should probbaly look at that direction.