Python Web 版本tailf, grep

Posted IT胖子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python Web 版本tailf, grep相关的知识,希望对你有一定的参考价值。

Python有一个插件,可以让我们在网页上实现类似于Linux 下tailf, grep和awk的功能。这个插件的名字是tailon。

安装插件,

pip install tailon

 启动服务:

tailon -f /var/log/nginx/* /var/log/apache/{access,error}.log

 服务如果正常启动就可以在浏览器里使用:http://localhost:8080 访问。

 更多命令:

Usage: tailon [-c path] [-f path [path ...]] [-h] [-d] [-v]
              [--output-encoding enc] [--input-encoding enc] [-b addr:port]
              [-r path] [-p type] [-u user:pass] [-a] [-f] [-t num]
              [-m [cmd [cmd ...]]] [--no-wrap-lines]

Tailon is a web app for looking at and searching through log files.

Required options:
  -c, --config path               yaml config file
  -f, --files path [path ...]     list of files or file wildcards to expose

General options:
  -h, --help                      show this help message and exit
  -d, --debug                     show debug messages
  -v, --version                   show program‘s version number and exit
  --output-encoding enc           encoding for output
  --input-encoding enc            encoding for input and output (default utf8)

Server options:
  -b, --bind addr:port            listen on the specified address and port
  -r, --relative-root path        web app root path
  -p, --http-auth type            enable http authentication (digest or basic)
  -u, --user user:pass            http authentication username and password
  -a, --allow-transfers           allow log file downloads
  -F, --follow-names              allow tailing of not-yet-existent files
  -t, --tail-lines num            number of lines to tail initially
  -m, --commands [cmd [cmd ...]]  allowed commands (default: tail grep awk)

User-interface options:
  --no-wrap-lines                 initial line-wrapping state (default: true)

Example config file:
  bind: 0.0.0.0:8080      # address and port to bind on
  allow-transfers: true   # allow log file downloads
  follow-names: false     # allow tailing of not-yet-existent files
  relative-root: /tailon  # web app root path (default: ‘‘)
  commands: [tail, grep]  # allowed commands
  tail-lines: 10          # number of lines to tail initially
  wrap-lines: true        # initial line-wrapping state

  files:
    - ‘/var/log/messages‘
    - ‘/var/log/nginx/*.log‘
    - ‘/var/log/xorg.[0-10].log‘
    - ‘/var/log/nginx/‘   # all files in this directory
    - ‘cron‘:             # it‘s possible to add sub-sections
        - ‘/var/log/cron*‘

  http-auth: basic        # enable authentication (optional)
  users:                  # password access (optional)
    user1: pass1

Example command-line:
  tailon -f /var/log/messages /var/log/debug -m tail
  tailon -f ‘/var/log/cron*‘ -a -b localhost:8080
  tailon -f /var/log/ -p basic -u user1:pass1 -u user2:pass2
  tailon -c config.yaml -d

 

以上是关于Python Web 版本tailf, grep的主要内容,如果未能解决你的问题,请参考以下文章

ReocketMq常用命令

利用pyinotify监控文件内容,像tailf命令但比它更强

是否可以结合使用tail和grep? [复制]

tailf 跟踪日志文件

[Project] Simulate HTTP Post Request to obtain data from Web Page by using Python Scrapy Framework(代

Python实现简易HTTP服务器与MINI WEB框架(利用WSGI实现服务器与框架解耦)