lnav README

The project's README from github.com/tstack/lnav. As one markdown file: README.md.

Build Docs Coverage Status lnav Gurubase

Discord Logo

This is the source repository for lnav, visit https://lnav.org for a high level overview.

LNAV -- The Logfile Navigator

The Logfile Navigator is a log file viewer for the terminal. Given a set of files/directories, lnav will:

Then, in the lnav TUI, you can:

Screenshot

The following screenshot shows a mix of syslog and web access log files. Failed requests are shown in red. Identifiers, like IP address and PIDs are semantically highlighted.

Screenshot

Why not just use tail/grep/less?

The standard Unix utilities are great for processing raw text lines, however, they do not understand log messages. Tail can watch multiple files at a time, but it won't display messages in order by time and you can't scroll backwards. Grep will only find matching lines, but won't return a full multi-line log message. Less can only display a single file at a time. Also, none of these basic tools handle compressed files.

Try online before installing

You can SSH into a demo node to play with lnav before installing.

The "playground" account starts lnav with a couple of log files as an example:

$ ssh [email protected]

The "tutorial 1" account is an interactive tutorial that can teach you the basics of operation:

$ ssh [email protected]

Installation

Download a statically-linked binary for Linux/MacOS/Windows from the release page

Brew on MacOS

$ brew install lnav

FreeBSD

$ pkg install lnav

Usage

Simply point lnav at the files or directories you want to monitor, it will figure out the rest:

$ lnav /path/to/file1 /path/to/dir ...

The lnav TUI will pop up right away and begin indexing the files. Progress is displayed in the "Files" panel at the bottom. Once the indexing has finished, the LOG view will display the log messages that were recognized[^1]. You can then use the usual hotkeys to move around the view (arrow keys or j/k/h/l to move down/up/left/right).

See the Usage section of the online documentation for more information.

[^1]: Files that do not contain log messages can be seen in the TEXT view (reachable by pressing t).

Usage with systemd-journald

On systems running systemd-journald, you can use lnav as the pager:

$ journalctl | lnav

or in follow mode:

$ journalctl -f | lnav

Since journalctl's default output format omits the year, if you are viewing logs which span multiple years you will need to change the output format to include the year, otherwise lnav gets confused:

$ journalctl -o short-iso | lnav

It is also possible to use journalctl's json output format and lnav will make use of additional fields such as PRIORITY and _SYSTEMD_UNIT:

$ journalctl -o json | lnav

In case some MESSAGE fields contain special characters such as ANSI color codes which are considered as unprintable by journalctl, specifying journalctl's -a option might be preferable in order to output those messages still in a non-binary representation:

$ journalctl -a -o json | lnav

If using systemd v236 or newer, the output fields can be limited to the ones actually recognized by lnav for increased efficiency:

$ journalctl -o json --output-fields=MESSAGE,PRIORITY,_PID,SYSLOG_IDENTIFIER,_SYSTEMD_UNIT | lnav

If your system has been running for a long time, for increased efficiency you may want to limit the number of log lines fed into lnav, e.g. via journalctl's -n or --since=... options.

In case of a persistent journal, you may want to limit the number of log lines fed into lnav via journalctl's -b option.

Support

Please file issues on this repository or use the discussions section. The following alternatives are also available:

Contributing

Building From Source

Prerequisites

The following software packages are required to build lnav:

Build

Lnav follows the usual GNU style for configuring and installing software:

Run ./autogen.sh if compiling from a cloned repository.

$ ./configure
$ make
$ sudo make install

See Also

Angle-grinder is a tool to slice and dice log files on the command-line. If you're familiar with the SumoLogic query language, you might find this tool more comfortable to work with.

Code Signing Policy

Free code signing provided by SignPath.io, certificate by SignPath Foundation.

This program will not transfer any information to other networked systems unless specifically requested by the user or the person installing or operating it.

Acknowledgements

Many thanks to:

lnav (tstack/lnav)

Searching Database…

10.7K ·GitHub
这是什么?lnav 是一个终端里的日志文件查看器。把文件或目录交给它,它会自动识别格式,把它们按时间顺序合并到一个视图里,并在有新消息时持续跟踪显示。
它和直接用 tail、grep 或 less 有什么不同?那些工具只能处理原始文本行,而 lnav 能理解日志消息。tail 不能按时间顺序显示消息,也不能往回滚动;grep 无法返回完整的多行消息;less 一次只能看一个文件;而且它们都处理不了压缩文件。
怎么安装和启动?从发布页面下载适用于 Linux、MacOS 或 Windows 的静态链接二进制文件,MacOS 上也可以用 Brew。然后对要监控的文件或目录直接运行 'lnav' 即可——终端界面会立即打开并开始建立索引。
要让它跑起来还需要安装别的东西吗?不用——发布页面上的二进制文件是静态链接的,可以独立运行。如果你改为自己从源码编译,则需要 C++14 编译器、libpcre2、SQLite 3.9+、zlib、bzip2、libcurl 7.23+、libarchive、libunistring、tshark,以及用于 PRQL 编译器的 cargo/Rust。
我打开的每个文件都会显示在日志视图里吗?只有 lnav 能识别出日志消息的文件才会出现在 LOG 视图中。识别不出日志消息的文件仍可以在单独的 TEXT 视图中查看——按 t 即可切换过去。
lnav 会通过网络发送数据吗?根据它的代码签名政策,不会——除非用户或安装者明确要求,否则它不会向其他联网系统传输任何信息。
在 lnav 视图里我具体能做些什么?用 e/E 跳转到上一个或下一个错误,用 / 按正则表达式搜索,用正则表达式过滤或高亮消息,按 P 美化打印 JSON-lines 之类的结构化文本,按 i 查看消息随时间分布的直方图。
我能用 SQL 分析我的日志吗?可以——它内置了 SQLite。在终端界面里按 ; 即可对已建立索引的消息运行查询,消息过滤器也可以用 SQLite 表达式,而不只是普通的正则表达式。
安装之前能先试用一下 lnav 吗?可以,通过 SSH 就行。'ssh [email protected]' 会带着几个示例日志文件启动 lnav,'ssh [email protected]' 则会运行一个交互式教程,讲解基本操作。
它支持 systemd-journald 的日志吗?支持——lnav 可以作为 journalctl 的分页器使用,包括跟随模式,而且 journalctl 的 JSON 输出还能提供 PRIORITY 等额外字段。在长期运行的系统上,建议用参数限制输入范围(比如 --since 或 -b)以提高效率。
What are similar projects?glances, goaccess, k9s, sampler, osquery, witr, btop, apprise
Creator
tstack
Size
69 MB
Stars
10.7K
Age
17y
Commits · 90 Days