If you have a problem with your computer, you may have to go through log files, or as a software engineer, you may be looking for clues about a bug in a debug or error log. It can be done in any text editor, but there may be a better way thanks to lnav Log Files Navigator that allows checking those files more easily and efficiently in a Mac OS or Linux terminal.
The following log files are supported by default even if they are compressed with gzip or bzip2:
- Common Web Access Log format
- CUPS page_log
- VMware ESXi/vCenter Logs
- “Generic” – Any message that starts with a timestamp
lnav is open-source software released under a BSD-2 clause in Github. It’s not new at all as some commits were made in January 2010, but it’s new to me, and hopefully to some of you as well.
There are various ways to install it, but the easiest way in Ubuntu is to install it as a snap.
sudo snap install lnav
Launching lnav with no other parameters will open /var/log/syslog automatically.
If you’re familiar with Vi/Vim, using lnav should be fairly easy as many of the commands are the same. For example, we can search with “/” to filter messages with a specific string.
You can select the next/previous occurrence of the string with n/N. Tabulation is also supported so you don’t need to copy/paste or type longer strings.
If you want to master the program and make the most of it, you’ll need to read the documentation for command line parameters and shortcuts, as there are so many options.
Some of the cool features of the program include Single Log View showing all logs in a single window based on message timestamps, filtering content with regular expressions, a Timeline View showing when most errors and warnings occurred, Pretty-Print View to reformat structured data such as XML or JSON, and more.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
5 Replies to “Lnav Log Files Navigator Helps You Analyze Log Files in a Mac OS or Linux Terminal”
> the easiest way in Ubuntu is to install it as a snap
But then you have to deal with AppArmor when trying to access logs outside of standard log locations. lnav is also available in the usual package repos, just more outdated as always. On Bionic for example:
Currently, the snap package of lnav can read log files from “/var/log/” and from the users’s home directory.
You can specify lnav to read arbitrary logs from any file in the above directories.
Snap packages have a private tmp directory, for lnav it is “/tmp/snap.lnav”. Therefore, old habits of sharing files in “/tmp” will not work.
It is also possible to get “lnav” to read log files from attached disks. The developer has to ask for this permission and should be granted.
More on this at https://github.com/tstack/lnav/issues/525
That’s a great tip! Thx
The snap isn’t working for me on 20.04. I’ve tried it using the default confinement, –classic (refused) and –devmode but in all cases it exits silently for any and all paths given.
On Focal, apt delivers version 0.8.5-2, and it works. 🙂
The snap package of lnav should work out-of-the-box on Ubuntu 20.04 LTS.
By default, it opens “/var/log/syslog”. If you get any error, it is a bug and you should report it.
Post here any details and I can I look into it.