You may know tail -f
, but here is a tool specifically designed to navigate
through log files: lnav
.
Viewing a changing log file
tail -f logfile
will wait for output of a log file, and your favorite editor
may warn you about a file change.
lnav logfile
will handle log file change.
logrotate
Most Linux distribution use logrotate
to handle log files rotation. The goal is to rotate logs when they are too big,
or too old. The shortcoming is that it creates multiples log files, in various
formats, with funny names.
syslog
becomes syslog.1
then syslog.1.gz
, syslog.2.gz
, …
lnav -r /var/log/syslog
will open /var/log/syslog
, and all rotated files!
Multiple log files
lnav
will display multiple log files in the same view (log entries sorted by time).
Example : lnav -r /var/log/syslog /var/log/auth.log
Shortcuts
A complete list of hotkeys is available here, but here are some I use everyday:
Navigation
Key | effect |
---|---|
Home or g | Top of the view |
End or G | Bottom of the view |
PgDn or space | Down a page |
PgUp or b | Up a page |
e/E | Next/previous error |
w/W | Next/previous warning |
f/F | Next/previous file |
Searching
Key | effect |
---|---|
/ | Search for lines matching a regular expression |
CTRL+] | Abort |
n/N | Next/previous hit |
~~~
Question, remark, bug? Don't hesitate to contact me or report a bug.