4个稳定版本

使用旧的Rust 2015

1.2.0 2018年12月2日
1.1.1 2018年11月24日
1.1.0 2018年11月23日
1.0.0 2018年11月11日

#1513解析实现

自定义许可

405KB
754

tztail

Build Status crates.io

tztail (TimeZoneTAIL) 允许您以您希望的时区查看日志。它的时区尾随。

安装

使用Homebrew

brew tap thecasualcoder/stable
brew install tztail

使用Cargo

cargo install tztail

用法

$ tztail --help
tztail (TimeZoneTAIL) allows you to view logs in the timezone you want

USAGE:
    tztail [FILE]

OPTIONS:
    -t, --timezone <TIMEZONE>    Sets the timezone in which output should be printed. (Default: local timezone)
    -f, --follow                 Follow the file indefinitely as changes are added. (Default: Off)
        --format <FORMAT>        Custom format for parsing dates. (Default: autodetected patterns)
    -h, --help                   Prints help information
    -V, --version                Prints version information

ARGS:
    <FILE>    File to tail. STDIN by default

特性

  • 支持一些标准格式,解析日志时将自动检测。
  • 如果格式非标准,可以指定自定义解析格式。有关格式,请参阅此处
  • 如果日志中存在,将自动检测源时区。示例(2014-11-28T12:00:09+0100 是CET)
  • 默认将日志输出到本地时区

演示

demo

可检测的格式

最常用的可检测格式

名称 示例
RFC2822 Fri, 28 Nov 2014 12:00:09 +0000
RFC3339 2014-11-28T12:00:09+0000
Nginx日志格式 04/Nov/2018:12:13:49 +0000

用例

此工具可用于在查看日志时将日志中的时间戳转换为任何所需的时区。例如,如果您的日志是UTC,但您想在不同的时区查看,例如亚洲/加尔各答(IST),则通过 tztail 将日志管道。

## Example usage
$ cat somelog # A log in UTC
2018-11-03 19:47:20.279044 I mvcc: finished scheduled compaction at 104794 (took 748.443µs)
2018-11-03 19:52:20.282913 I mvcc: store.index: compact 105127

$ cat somelog | tztail --timezone Asia/Kolkata # Timestamps converted to IST
2018-11-04 01:17:20.279044 I mvcc: finished scheduled compaction at 104794 (took 748.443µs)
2018-11-04 01:22:20.282913 I mvcc: store.index: compact 105127

它还允许指定自定义格式。

## Example usage
$ cat somelog # A log in non-standard format
2018-11-03 20:07:20 mvcc: store.index: compact 106120
2018-11-03 20:07:20 mvcc: finished scheduled compaction at 106120 (took 933.25µs)

$ cat somelog | tztail -t Asia/Kolkata --format "%Y-%m-%d %H:%M:%S"
2018-11-04 01:37:20 mvcc: store.index: compact 106120
2018-11-04 01:37:20 mvcc: finished scheduled compaction at 106120 (took 933.25µs)

从源代码构建

检出代码并在本地构建。需要rust编译器1.30或更高版本。

$ git clone https://github.com/thecasualcoder/tztail
$ cd tztail

# To build binary locally
$ cargo build --release

# To install binary locally in Cargo bin path
$ cargo install

# To run tests
$ cargo test

依赖关系

~4–13MB
~123K SLoC