lnav:日誌記錄檔檢視器 lnav,取代 more、cat

2024-09-02

lnav

官網:The Logfile Navigator

安裝方式:https://lnav.org/downloads

lnav 文字檔、log檔案檢視工具,以 C++ 所設計的 open source 工具

最大特色是可辨識不同的軟體的 log 檔格式,畫面上以格式化方式顯示,並且可以上、下翻頁捲動來瀏覽

搭配 SQL 語法 可以快速過濾出指定的資料。


不用急著安裝,官方有提供試用功能

輸入:

# ssh [email protected]
or
# ssh [email protected]



在使用 cat、more、tail或less 查看各軟體的 log 檔案時

會因為換行的關係,造成資料不易閱讀: undefined


改用 lnav 時:

# lnav access_log

undefined 可按 PageUp、PageDown、方向鍵來瀏覽資料



lnav 最方便的是

可使用 SQL 命令來過濾資料

例如:

找出 時間是 「2024/8/28 17:01:30 ~ 2024/8/28 17:02:00」 的 requests

命令是:

;SELECt * from access_log where log_time>='2024-08-28 17:01:30' AND log_time<='2024-08-28 17:02:00' undefined


找出 referer 網址有「wp-admin」,「method=POST」相關的 requests

命令是:

;select * from access_log where cs_referer like '%wp-admin%' AND cs_method='POST'

undefined



支援的 log 檔案格式

https://docs.lnav.org/en/v0.12.0/formats.html#log-formats

Name

Table Name

Description

Common Access Log

access_log

The default web access log format for servers like Apache.

Amazon ALB log

alb_log

Log format for Amazon Application Load Balancers

Generic Block

block_log

A generic format for logs, like cron, that have a date at the start of a block.

Bunyan log

bunyan_log

Bunyan JSON logging library for node.js

Candlepin log format

candlepin_log

Log format used by Candlepin registration system

Yum choose_repo Log

choose_repo_log

The log format for the yum choose_repo tool.

Cloudflare Access Log

cloudflare_json_log

Cloudflare Enterprise detailed logs of metadata

CloudVM Ram Log

cloudvm_ram_log

Periodic dumps of ram sizes

CUPS log format

cups_log

Log format used by the Common Unix Printing System

Dpkg Log

dpkg_log

The debian dpkg log.

Amazon ELB log

elb_log

Log format for Amazon Elastic Load Balancers

engine log

engine_log

The log format for the engine.log files from RHEV/oVirt

Common Error Log

error_log

The default web error log format for servers like Apache.

ESXi Syslog

esx_syslog_log

Format specific to the ESXi syslog

Fsck_hfs Log

fsck_hfs_log

Log for the fsck_hfs tool on Mac OS X.

GitHub Events Log

github_events_log

Format for the public GitHub timeline from gharchive.org

Glog

glog_log

The google glog format.

HAProxy HTTP Log Format

haproxy_log

The HAProxy log format

Java log format

java_log

Log format used by log4j and output by most java programs

journalctl JSON log format

journald_json_log

Logger format as created by systemd journalctl -o json

Katello log format

katello_log

Log format used by katello and foreman as used in Satellite 6.

Nextcloud server logs

nextcloud

Nextcloud JSON server logs audit.log, flow.log, and nextcloud.log

OpenAM Log

openam_log

The OpenAM identity provider.

OpenAM Debug Log

openamdb_log

Debug logs for the OpenAM identity provider.

OpenStack log format

openstack_log

The log format for the OpenStack log files

CUPS Page Log

page_log

The CUPS server log of printed pages.

Papertrail Service

papertrail_log

Log format for the papertrail log management service

Packet Capture

pcap_log

Internal format for pcap files

Process State

procstate_log

Periodic dumps of process state

Redis

redis_log

The Redis database

S3 Access Log

s3_log

S3 server access log format

SnapLogic Server Log

snaplogic_log

The SnapLogic server log format.

SSSD log format

sssd_log

Log format used by the System Security Services Daemon

Strace

strace_log

The strace output format.

sudo

sudo_log

The sudo privilege management tool.

Syslog

syslog_log

The system logger format found on most posix systems.

TCF Log

tcf_log

Target Communication Framework log

TCSH History

tcsh_history

The tcsh history file format.

UniFi iptables log

unifi_iptables_log

The UniFi gateway iptables logger format (for /var/log/iptables).

UniFi log

unifi_log

The UniFi gateway messages logger format (for /var/log/messages).

Uwsgi Log

uwsgi_log

The uwsgi log format.

Vdsm Logs

vdsm_log

Vdsm log format

VMKernel Logs

vmk_log

The VMKernel’s log format

VMware Logs

vmw_log

One of the log formats used in VMware’s ESXi and vCenter software.

VMware vSphere log format

vmw_py_log

The log format for some VMware vSphere services

VMware Go Log

vmw_vc_svc_log

Log files for go-based logs

VMWare PostgreSQL

vpostgres_log

Format for vpostgresql log files with format ‘%m %c %x %d %u %r %p %l’

RHN server XMLRPC log format

xmlrpc_log

Generated by Satellite’s XMLRPC component

lnav 其它特色功能

https://lnav.org/features

  • Single Log View
  • Automatic Log Format Detection
  • Filters
  • Timeline View
  • Pretty-Print View
  • Query Logs Using SQL
  • “Live” Operation
  • Themes
  • Syntax Highlighting
  • Tab-completion
  • Custom Keymaps
  • Sessions
  • Headless Mode

lnavhigoopro推薦第一

分類:Linux      154
Tag aaa , log , lnav ,
留言

留言
top