LNAV: interesting log file analyzer for the commandline

Off course, the web log file viewer from OH (frontail) is very nice, but sometimes you need a little more. And sometimes, the commandline is where you are. You might consider using lnav (Logfile NAVigation). I tried several of them, but this one seems to be very powerful.

It can ready the openhab.log file, even if its compressed ! And it is constantly updating, like “tail -f” :grinning:

Start it in the shell like:

lnav /etc/openhab/log/openhab.log.7.gz

An impression of how it looks, with two patterns marked:

Some usefull hotkeys:

  • e / E : jump to next/previous ERROR ( :+1:I especially like this one)
  • w / W: jump to next/previous WARNING
  • d / D : forward / backward 24 hours
  • 0 / shift 0 : next / previous day
  • ctrl-r : reset all filters and highlights
  • i : show a histogram with number of errors per day :exclamation:
  • p / shift p : show / stop showing JSON messages in a pretty way :exclamation:
  • / : search a string of regular expression
  • g / G : go to top or bottom of the file

Some interesting commands (use : to get into command mode) :

  • :filter-in <regex-searchstring> : show only lines matching the regex searchstring
  • :filter-out <regex-searchstring> : do not show matching lines
  • :highlight <regex-searchstring> : mark all matching strings with a color (you can apply serveral on top of each other)

Nice, but the default file (sudo apt install lnav) is a very old one. Download the sources and install that new version using:

tar xvfz lnav-0.11.2.tar.gz
cd lnav-0.11-2
sudo apt install libcurl4-openssl-dev ncurses-dev libpcre2-dev libreadline-dev libsqlite3-dev
make # and wait an hour or so
sudo make install

Note that is possible to create your own format. The Openhab log format is pretty much recognized. I tried to create this format, but did not succeed yet. I should be possible to filter out the block containing text about the module of OH which is not always interesting:

2023-12-19 20:05:04.016 [DEBUG] [nal.protocol.ZWaveTransactionManager] - Uncompressed format
2023-12-19 20:05:04.016 [DEBUG] […] - Compressed format

This would make the output less wide. But let’s save that for later. And a whole lot of other features :sweat_smile:

I’ll hope you enjoy this tool. If not, be happy with any other tool you like.

2 Likes

Can it view multiple log files at once?

I use multitail and being able to watch both openhab.log and events.log at the same time and add markers is a feature I can no longer live without.

1 Like

Yes

1 Like

Well, it depends upon how you look at it.

Yes, lnav can read multiple files in one view, just like multitail:

lnav openhab.log events.log

In the screendump, you see openhab.log output and events.log output in one view :

Here, a line from openhab.log and events.log are marked (black background).

Furthermore, the filters, bookmarks, searches, and a lot more, are saved for next sessions (which can also a bit confusing for first-time users).

The way you can use sql command to create reports is impressive, although I cannot find an easy use case for openhab users:

image

However, multitail can do multiple windows. That’s not what lnav can.

It’s what you like and know :grinning: