Some details about lnav tool.
Useful documentation:
- Lnav docs: https://docs.lnav.org/en/latest/
Lnav (Logs navigator) is a tool to watch and analyze log files from a terminal.
Installation
To install lnav on Linux:
# On debian based distrib
sudo apt install lnav
# On fedora/centos/rhel distrib
sudo yum install lnav
Check the installed version
lnav -V
Usage
Launch lnav on a log file with:
# Open `/var/log/messages` log file
lnav /var/log/messages
# Open all the `/var/log/messages` log files, including the archived ones (e.g. `messages-2023-02-19`)
lnav /var/log/messages*
Useful hotkeys in lnav:
?
: open lnav helpq
: quit the current view, or lnav/
: start a search:
: execute an lnav command=
: Pause/unpause logs loadingCtrl
+r
: Reset the current session state (includes filters, bookmarks, hidden fields)PgUp
/PgDn
: Up/Down a pageHome
/End
: Top/Bottom of the opened logse
/Shift
+e
: Next/Previous error0
/Shift
+0
: Next/Previous day
The full list can be found in the hotkeys doc.
Search
To search in the logs, type the key /
in lnav, followed by a regex of the search:
# search my-service in the logs
/my-service
# search an ipv4 addr in the logs
/(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}
Commands
To start a command, type :
in lnav. The commands history can be navigated with the up
and down
arrows.
Some useful commands:
filter-in <regex>
: Show only logs that match the regexfilter-out <regex>
: Don’t show logs that match the regexdisable-filter <regex>
: Disable a filter createdhide-lines-before
andhide-lines-after
: Hide lines before/after a date (e.g.hide-line-before 6am
to hide logs before today 6am, orhide-lines-before 2023-12-18T01:39:09.000
to hide lines before a specific datetime)show-lines-before-and-after
: Stop hiding lines before and after datesset-min-log-level <level>
: Set the minimum log level to view (can bedebug
,info
,warn
,error
)write-raw-to <filename>
: write logs (example concatenated logs with filters) to another file. Starting with lnav version0.11.1
, an option--anonymize
allows to anonymize the IP addresses, URLs, MAC addresses, emails, etc… to share logs.
Commands generally support the TAB
completion.
The list of the supported commands can be found here: https://docs.lnav.org/en/latest/commands.html#reference.
PREVIOUSApache Benchmark