突出显示线程应用程序的日志

发布于 2024-10-31 08:00:28 字数 260 浏览 6 评论 0 原文

我有多线程应用程序的日志文件。每行都有众所周知的格式(例如,第三个字段是线程 ID)。其中一个字段是线程 ID。我希望我没有尝试重新发明轮子:)

无论如何,为了轻松阅读文件,我想到了两个可以提供帮助的选项:

  1. 突出显示与当前行具有相同线程 id 的所有行。

  2. 如果按下某个按键,则折叠所有具有其他线程 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:

  1. Highlight all lines with the same thread id as current line.

  2. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮湿 2024-11-07 08:00:28

按模式突出显示

这是一个用于突出显示(另一个用于清除)包含给定模式的所有行的函数,并在模式本身上强调突出显示。 “最后搜索”寄存器 @/ 也设置为请求的模式,因此 n/N 在正常模式下向前/向后跳转匹配线。 l (相当于大多数安装中的 \l)是突出显示包含 WORD 在光标下。

highlight def link xHiLine Special
highlight def link xHiPatt String

function! ClearHighlight()
    syn clear xHiLine
    syn clear xHiPatt
    let @/ = ''
endfunction

function! HighlightPattern(patt)
    call ClearHighlight()
    if a:patt != ''
        echo "Highlighting pattern: ".a:patt
        exec "syn match xHiPatt \"".a:patt."\" contained"
        exec "syn match xHiLine \".*".a:patt.".*\" contains=xHiPatt"
        let @/ = a:patt
    endif
endfunction

map <Leader>l :call HighlightPattern(expand("<cWORD>"))<CR>
map <Leader>c :call ClearHighlight()<CR>

按模式折叠

有关基于模式折叠的示例,请查看 Show-Hide Vim插件。它提供了两个命令,SHOWHIDE,以及一些快捷方式映射。例如, :SHOW thread=1234 将折叠除包含 thread=1234 的行之外的所有行,而正常模式下的 zs 将显示包含以下内容的行:光标下的单词。 [您可能需要创建备用地图,例如 zS,以使用 而不是 .]

构建模式

如果既不是 也不是 提取足够独特的过滤模式(或避免将光标移动到正确的字段),创建另一个类似下面的函数并从映射中调用它。

function! GetField(num)
    let toks = split(getline('.'))
    if len(toks) >= a:num
        return toks[a:num-1]
    endif
    return ''
endfunction

map <Leader>hl :call HighlightPattern(GetField(3))<CR>
map <Leader>fl :exec "SHOW ".GetField(3)<CR>

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 so n/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 the WORD under your cursor.

highlight def link xHiLine Special
highlight def link xHiPatt String

function! ClearHighlight()
    syn clear xHiLine
    syn clear xHiPatt
    let @/ = ''
endfunction

function! HighlightPattern(patt)
    call ClearHighlight()
    if a:patt != ''
        echo "Highlighting pattern: ".a:patt
        exec "syn match xHiPatt \"".a:patt."\" contained"
        exec "syn match xHiLine \".*".a:patt.".*\" contains=xHiPatt"
        let @/ = a:patt
    endif
endfunction

map <Leader>l :call HighlightPattern(expand("<cWORD>"))<CR>
map <Leader>c :call ClearHighlight()<CR>

Folding by pattern

For an example of folding based on patterns, check out the Show-Hide Vim plug-in. It provides two commands, SHOW and HIDE, and a few shortcut maps. For example, :SHOW thread=1234 will fold all lines except those that contain thread=1234, while zs in normal mode will show lines containing the word under your cursor. [You may want to create an alternate map, such as zS, 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.

function! GetField(num)
    let toks = split(getline('.'))
    if len(toks) >= a:num
        return toks[a:num-1]
    endif
    return ''
endfunction

map <Leader>hl :call HighlightPattern(GetField(3))<CR>
map <Leader>fl :exec "SHOW ".GetField(3)<CR>
猥琐帝 2024-11-07 08:00:28

您基本上正在寻找的是在日志文件之上构建的外部机制。
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文