lnav icon indicating copy to clipboard operation
lnav copied to clipboard

Navigate between log entries

Open e-pc opened this issue 4 years ago • 5 comments

Hi guys,

I enjoy the tool sooo much! Thanks a lot for it!

But is there a hot key or a command to move up and down between log entries? Sometimes I have huge multiline text in the message part in a log entry and takes me a while to navigate to preceding or following message.

Cheers, e

e-pc avatar Mar 04 '20 09:03 e-pc

Annotation 2020-03-04 100847

Here is an example.

e-pc avatar Mar 04 '20 09:03 e-pc

If you're able to update to the top-of-tree, you can assign a pair of keys to execute SQL statements that should do what you want.

The commands to execute within lnav are the following (note that you should run each command separately):

:config /ui/keymap_def/default/x2c/command ;UPDATE lnav_views SET top = (SELECT log_line from all_logs where log_line < log_top_line() order by log_line desc limit 1) WHERE name = 'log'
:config /ui/keymap_def/default/x2e/command ;UPDATE lnav_views SET top = (SELECT log_line from all_logs where log_line > log_top_line() order by log_line asc limit 1) WHERE name = 'log'
:save-config

The :config commands change the keymap and assign commands to keys with the given hex codes. In this case x2c (a comma) and x2e (a period). Feel free to change that to whatever you want.

tstack avatar Mar 04 '20 18:03 tstack

The v0.9.0 release added official support for custom keymaps, but the commands are slightly different from above:

:config /ui/keymap-defs/default/x2c/command ;UPDATE lnav_views SET top = (SELECT log_line from all_logs where log_line < log_top_line() order by log_line desc limit 1) WHERE name = 'log'
:config /ui/keymap-defs/default/x2e/command ;UPDATE lnav_views SET top = (SELECT log_line from all_logs where log_line > log_top_line() order by log_line asc limit 1) WHERE name = 'log'

tstack avatar Dec 13 '20 20:12 tstack

Just a note this should definitely be in the standard keymap once multi-line support (issue #813) is done. Actually there's no harm in having this in the standard keymap even now :)

piotr-dobrogost avatar Dec 21 '20 11:12 piotr-dobrogost

When viewing the first log entry and trying to go back or viewing the last log entry and trying to go forward there's the error ✘ error: Expecting an integer for column number 1 when using SQL from https://github.com/tstack/lnav/issues/716#issuecomment-744066279

piotr-dobrogost avatar Jan 11 '21 10:01 piotr-dobrogost