2022-08-29 01:55:32 +00:00
<!-- This is a comment for testing purposes -->
2021-02-13 20:41:48 +00:00
[![Build ](https://github.com/tstack/lnav/workflows/ci-build/badge.svg )](https://github.com/tstack/lnav/actions?query=workflow%3Aci-build)
2021-03-02 23:19:08 +00:00
[![Docs ](https://readthedocs.org/projects/lnav/badge/?version=latest&style=plastic )](https://docs.lnav.org)
2021-02-07 07:08:01 +00:00
[![Coverage Status ](https://coveralls.io/repos/github/tstack/lnav/badge.svg?branch=master )](https://coveralls.io/github/tstack/lnav?branch=master)
2022-08-29 01:55:32 +00:00
[![lnav ](https://snapcraft.io/lnav/badge.svg )](https://snapcraft.io/lnav)
2013-04-10 05:36:08 +00:00
2023-08-25 04:10:54 +00:00
[<img src="https://assets-global.website-files.com/6257adef93867e50d84d30e2/62594fddd654fc29fcc07359_cb48d2a8d4991281d7a6a95d2f58195e.svg" height="20" alt="Discord Logo"/> ](https://discord.gg/erBPnKwz7R )
2022-08-17 20:08:16 +00:00
2021-08-25 11:19:26 +00:00
_This is the source repository for **lnav** , visit [https://lnav.org ](https://lnav.org ) for a high level overview._
2013-08-30 15:55:49 +00:00
2017-05-09 18:02:38 +00:00
# LNAV -- The Logfile Navigator
2013-04-10 05:36:08 +00:00
2024-02-19 06:35:36 +00:00
The Logfile Navigator is a log file viewer for the terminal. Given a
2024-02-19 17:02:44 +00:00
set of files/directories, **lnav** will:
2020-09-16 04:38:30 +00:00
2024-02-19 06:35:36 +00:00
- decompress as needed;
- detect their format;
- merge the files together by time into a single view;
2024-02-19 17:02:44 +00:00
- tail the files, follow renames, find new files in directories;
- build an index of errors and warnings;
- [pretty-print JSON-lines ](https://docs.lnav.org/en/latest/formats.html#json-lines ).
2020-09-16 04:38:30 +00:00
2024-02-19 06:35:36 +00:00
Then, in the **lnav** TUI, you can:
2013-04-10 05:36:08 +00:00
2024-02-19 06:35:36 +00:00
- jump quickly to the previous/next error ([press `e` /`E`](https://docs.lnav.org/en/latest/hotkeys.html#spatial-navigation));
- search using regular expressions ([press `/` ](https://docs.lnav.org/en/latest/hotkeys.html#spatial-navigation));
- highlight text with a regular expression ([`:highlight`](https://docs.lnav.org/en/latest/commands.html#highlight-pattern) command);
- filter messages using [regular expressions ](https://docs.lnav.org/en/latest/usage.html#regular-expression-match ) or [SQLite expressions ](https://docs.lnav.org/en/latest/usage.html#sqlite-expression );
2024-02-19 06:37:58 +00:00
- pretty-print structured text ([press `P` ](https://docs.lnav.org/en/latest/ui.html#pretty));
- view a histogram of messages over time ([press `i` ](https://docs.lnav.org/en/latest/ui.html#hist));
2024-02-19 06:35:36 +00:00
- query messages using SQLite ([press `;` ](https://docs.lnav.org/en/latest/sqlext.html))
2013-04-10 05:36:08 +00:00
2024-02-19 06:35:36 +00:00
## Screenshot
2020-09-16 04:38:30 +00:00
2024-02-19 14:52:41 +00:00
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.
2024-02-19 06:35:36 +00:00
2024-02-19 14:52:41 +00:00
[![Screenshot ](docs/assets/images/lnav-front-page.png )](docs/assets/images/lnav-front-page.png)
2020-09-16 04:38:30 +00:00
2024-02-19 14:39:32 +00:00
## 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.
2024-02-19 14:52:41 +00:00
## 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 playground@demo.lnav.org` ](ssh://playground@demo.lnav.org )
The "tutorial 1" account is an interactive tutorial that can teach
you the basics of operation:
[`$ ssh tutorial1@demo.lnav.org` ](ssh://tutorial1@demo.lnav.org )
2017-05-09 18:02:38 +00:00
## Installation
2013-04-10 05:36:08 +00:00
2021-03-23 20:47:02 +00:00
[Download a statically-linked binary for Linux/MacOS from the release page ](https://github.com/tstack/lnav/releases/latest#release-artifacts )
2016-05-31 13:18:37 +00:00
2024-02-19 14:39:32 +00:00
### Brew on MacOS
```console
$ brew install lnav
```
2017-05-09 18:02:38 +00:00
## Usage
2013-04-10 05:36:08 +00:00
2024-02-19 06:35:36 +00:00
Simply point **lnav** at the files or directories you want to
monitor, it will figure out the rest:
2013-04-10 05:36:08 +00:00
2024-02-19 14:39:32 +00:00
```console
$ lnav /path/to/file1 /path/to/dir ...
2021-02-08 05:30:02 +00:00
```
2013-04-10 05:36:08 +00:00
2024-02-19 06:35:36 +00:00
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
2024-02-19 14:54:40 +00:00
the log messages that were recognized[^1]. You can then use the
2024-02-19 06:35:36 +00:00
usual hotkeys to move around the view (arrow keys or
`j` /`k`/`h`/`l` to move down/up/left/right).
2013-04-10 05:36:08 +00:00
2024-02-19 14:39:32 +00:00
See the [Usage section ](https://docs.lnav.org/en/latest/usage.html )
of the online documentation for more information.
2024-02-19 14:56:15 +00:00
[^1]: Files that do not contain log messages can be seen in the
TEXT view (reachable by pressing `t` ).
2013-04-10 05:36:08 +00:00
2017-05-09 18:02:38 +00:00
### Usage with `systemd-journald`
2017-04-19 11:19:47 +00:00
On systems running `systemd-journald` , you can use `lnav` as the pager:
2021-02-08 05:30:02 +00:00
```
$ journalctl | lnav
```
2017-04-19 11:19:47 +00:00
or in follow mode:
2021-02-08 05:30:02 +00:00
```
$ journalctl -f | lnav
```
2017-04-19 11:19:47 +00:00
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:
2021-02-08 05:30:02 +00:00
```
$ journalctl -o short-iso | lnav
```
2017-04-19 11:19:47 +00:00
2018-08-25 15:32:34 +00:00
It is also possible to use `journalctl` 's json output format and `lnav`
2021-02-08 05:30:02 +00:00
will make use of additional fields such as PRIORITY and \_SYSTEMD_UNIT:
2018-08-25 15:32:34 +00:00
2021-02-08 05:30:02 +00:00
```
$ journalctl -o json | lnav
```
2018-08-25 15:32:34 +00:00
2018-08-25 16:38:55 +00:00
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
2022-08-17 20:11:57 +00:00
to output those messages still in a non-binary representation:
2018-08-25 16:38:55 +00:00
2021-02-08 05:30:02 +00:00
```
$ journalctl -a -o json | lnav
```
2018-08-25 16:38:55 +00:00
2018-08-25 15:32:34 +00:00
If using systemd v236 or newer, the output fields can be limited to
the ones actually recognized by `lnav` for increased efficiency:
2021-02-08 05:30:02 +00:00
```
$ journalctl -o json --output-fields=MESSAGE,PRIORITY,_PID,SYSLOG_IDENTIFIER,_SYSTEMD_UNIT | lnav
```
2018-08-25 15:32:34 +00:00
2017-04-19 11:19:47 +00:00
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.
2018-08-25 15:32:34 +00:00
In case of a persistent journal, you may want to limit the number
of log lines fed into `lnav` via `journalctl` 's `-b` option.
2022-08-17 20:11:57 +00:00
## Support
Please file issues on this repository or use the discussions section.
The following alternatives are also available:
- [support@lnav.org ](mailto:support@lnav.org )
- [Discord ](https://discord.gg/erBPnKwz7R )
- [Google Groups ](https://groups.google.com/g/lnav )
2021-03-23 20:47:02 +00:00
## Links
2013-04-10 05:36:08 +00:00
2021-03-23 20:47:02 +00:00
- [Main Site ](https://lnav.org )
- [**Documentation** ](https://docs.lnav.org ) on Read the Docs
- [Internal Architecture ](ARCHITECTURE.md )
2013-04-10 05:36:08 +00:00
2021-03-23 20:47:02 +00:00
## Contributing
- [Become a Sponsor on GitHub ](https://github.com/sponsors/tstack )
### Building From Source
#### Prerequisites
The following software packages are required to build lnav:
- gcc/clang - A C++14-compatible compiler.
2022-09-12 14:18:26 +00:00
- libpcre2 - The Perl Compatible Regular Expression v2 (PCRE2) library.
2021-03-23 20:47:02 +00:00
- sqlite - The SQLite database engine. Version 3.9.0 or higher is required.
- ncurses - The ncurses text UI library.
- readline - The readline line editing library.
- zlib - The zlib compression library.
- bz2 - The bzip2 compression library.
- libcurl - The cURL library for downloading files from URLs. Version 7.23.0 or higher is required.
- libarchive - The libarchive library for opening archive files, like zip/tgz.
2021-11-05 22:13:16 +00:00
- wireshark - The 'tshark' program is used to interpret pcap files.
2024-03-28 04:27:03 +00:00
- cargo/rust - The Rust language is used to build the PRQL compiler.
2021-03-23 20:47:02 +00:00
#### Build
Lnav follows the usual GNU style for configuring and installing software:
Run `./autogen.sh` if compiling from a cloned repository.
2022-08-22 05:02:46 +00:00
```console
2021-03-23 20:47:02 +00:00
$ ./configure
$ make
$ sudo make install
```
2013-04-10 05:36:08 +00:00
2020-09-12 21:06:23 +00:00
## See Also
2013-04-10 05:36:08 +00:00
2018-12-13 14:16:40 +00:00
[Angle-grinder ](https://github.com/rcoh/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.