6

每天学习一个命令:高级日志查看工具 lnav

 7 months ago
source link: https://einverne.github.io/post/2024/02/the-logfile-navigator-lnav.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

每天学习一个命令:高级日志查看工具 lnav

Posted on 02/10/2024 , Last modified on 02/10/2024 by Ein Verne | View revision history

The Logfile Navigator 是一个高级的日志查看工具,后面简写为 lnav。

早上在看 [[Logdy]] 的时候(一款可以将终端的输出 (stdout)发送给浏览器 UI 界面,在可视化界面中检索浏览的开源工具),在作者发帖的讨论中,看到有人推荐 lnav 这一款工具,在本地开发的时候,用 lnav 来查看日志。1

在不知道 lnav 之前,我一直都是使用 tail -f, less, zless, more 来查看日志的,但是 less 这一些工具都是不带高亮的,所以每一次都需要通过搜索来找到自己的想要的内容,但看到 lnav 的介绍立即就看到了 lnav 的高亮显示,立马就尝试了一下。

Ubuntu 下

sudo apt install lnav

完整的命令行参数

❯ lnav -h
usage: lnav [options] [logfile1 logfile2 ...]

A curses-based log file viewer that indexes log messages by type
and time to make it easier to navigate through files quickly.

Key bindings:
  ?     View/leave the online help text.
  q     Quit the program.

Options:
  -h         Print this message, then exit.
  -H         Display the internal help text.
  -I path    An additional configuration directory.
  -H         Display the internal help text.
  -I path    An additional configuration directory.
  -i         Install the given format files and exit.  Pass 'extra'
             to install the default set of third-party formats.
  -u         Update formats installed from git repositories.
  -C         Check configuration and then exit.
  -d file    Write debug messages to the given file.
  -V         Print version information.

  -a         Load all of the most recent log file types.
  -r         Recursively load files from the given directory hierarchies.
  -R         Load older rotated log files as well.
  -t         Prepend timestamps to the lines of data being read in
             on the standard input.
  -w file    Write the contents of the standard input to this file.

  -c cmd     Execute a command after the files have been loaded.
  -f path    Execute the commands in the given file.
  -n         Run without the curses UI. (headless mode)
  -q         Do not print the log messages after executing all
             of the commands or when lnav is reading from stdin.

Optional arguments:
  logfile1          The log files or directories to view.  If a
                    directory is given, all of the files in the
                    directory will be loaded.

Examples:
  To load and follow the syslog file:
    $ lnav

  To load all of the files in /var/log:
    $ lnav /var/log

  To watch the output of make with timestamps prepended:
    $ make 2>&1 | lnav -t

Version: lnav 0.8.5

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK