How to interactively filter a stream of logs using fzf and ripgrep. #4173
-
Hello. I am trying to make a function that will stream the contents of a log (Ex: docker or journal) , and be able to filter the stream using ripgrep. Is there any example or someone can give me some guidelines how can I do this? With some help from ChatGPT I got this, but I have no idea what I am doing. It can display and filter logs, but it´s not refreshing as new logs appear and the back and forth in the search is also not working 100%. docker logs --follow "$container" 2>&1 |
fzf --ansi \
--reverse \
--header="Streaming logs for container $container | Type to filter | Ctrl-C to exit" \
--preview 'echo {} | rg --color always --passthru ""' \
--preview-window=down:50%:follow \
--bind 'change:reload:echo {} | rg --color always --passthru ""' \
--no-clear Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There are some examples in the In a recent PR (#4079), a user demonstrated how to search for a keyword while displaying the line within the stream and its surrounding lines in the preview. Footnotes |
Beta Was this translation helpful? Give feedback.
fzf
is already an interactive grep filter. Simply usedocker logs --follow "$container" | fzf --exact
and start typing the keyword you're looking for. No need to useripgrep
.There are some examples in the
ADVANCED.md
12 or on the maintainer's website3.In a recent PR (#4079), a user demonstrated how to search for a keyword while displaying the line within the stream and its surrounding lines in the preview.
Footnotes
fzf/ADVANCED.md - Log tailing ↩
fzf/ADVANCED.md - Ripgrep integration ↩
junegunn.github.io: Browsing log streams | ju…