Skip to content

Commit

Permalink
new: time range filter added
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Jul 9, 2021
1 parent 49e22a5 commit cebba1e
Show file tree
Hide file tree
Showing 11 changed files with 561 additions and 46 deletions.
137 changes: 136 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.9.1"
version = "0.9.2"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -13,6 +13,7 @@ edition = "2018"
ansi_term = "0"
anyhow = "1"
atoi = "0"
atty = "0"
bitmask = "0"
bytefmt = "0"
chrono = { version = "0", features = ["serde"] }
Expand All @@ -26,7 +27,8 @@ derive_deref = "1"
error-chain = "0"
flate2 = "1"
heapless = "0"
atty = "0"
htp = "0"
humantime = "2"
itertools = "0"
num_cpus = "1"
platform-dirs = "0"
Expand Down
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ Log viewer which translates JSON logs into pretty human-readable representation.
Shows only messages with field `provider` containing sub-string `string`.
### Filtering by time range.
- Command
```
$ hl example.log --since 'Jun 19 11:22:33' --until yesterday
```
Shows only messages occurred after Jun 19 11:22:33 UTC of the current year (or of the previous one if current date is less than Jun 19 11:22:33) and until yesterday midnight.
- Command
```
$ hl example.log --since -3d
```
Shows only messages for the last 48 hours.
- Command
```
$ hl example.log --until '2021-06-01 18:00:00' --local
```
Shows only messages occurred before 6 PM on 1st Jun 2021 in local time as well as show timestamps in local time.
### Hiding or showing selected fields.
- Command
Expand Down Expand Up @@ -170,7 +194,7 @@ Log viewer which translates JSON logs into pretty human-readable representation.
### Complete set of options and flags
```
hl 0.8.13
hl 0.9.2
JSON log converter to human readable representation

USAGE:
Expand All @@ -195,7 +219,7 @@ OPTIONS:
-f, --filter <filter>...
Filtering by field values in one of forms <key>=<value>, <key>~=<value>, <key>!=<value>, <key>!~=<value>

-h, --hide <hide>... An exclude-list of keys
-h, --hide <hide>... Hide fields with the specified keys
--interrupt-ignore-count <interrupt-ignore-count>
Number of interrupts to ignore, i.e. Ctrl-C (SIGINT) [default: 3]

Expand All @@ -206,7 +230,10 @@ OPTIONS:
--paging <paging>
Output paging options, one of { auto, always, never } [default: auto]

-H, --show <show>... An include-list of keys
-H, --show <show>... Hide all fields except fields with the specified keys
--since <since>
Filtering by timestamp >= the value (--time-zone and --local options are honored)

--theme <theme>
Color theme, one of { auto, dark, dark24, light } [default: dark]

Expand All @@ -216,6 +243,9 @@ OPTIONS:
-Z, --time-zone <time-zone>
Time zone name, see column "TZ database name" at
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones [default: UTC]
--until <until>
Filtering by timestamp <= the value (--time-zone and --local options are honored)


ARGS:
<FILE>... Files to process
Expand Down
5 changes: 4 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ impl App {
let n = self.options.concurrency;
let sfi = Arc::new(SegmentBufFactory::new(self.options.buffer_size));
let bfo = BufFactory::new(self.options.buffer_size);
let settings = ParserSettings::from(&self.options.settings);
let settings = ParserSettings::new(
&self.options.settings,
self.options.filter.since.is_some() || self.options.filter.until.is_some(),
);
let parser = Parser::new(&settings);
thread::scope(|scope| -> Result<()> {
// prepare receive/transmit channels for input data
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub enum Error {
"64KB"
)]
InvalidSize(String),
#[error("cannot recognize time {0:?}")]
UnrecognizedTime(String),
#[error("zero size")]
ZeroSize,
}
Expand Down
2 changes: 1 addition & 1 deletion src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl RecordFormatter {
// time
//
styler.set(buf, Element::Time);
if let Some(ts) = rec.ts() {
if let Some(ts) = &rec.ts {
aligned_left(buf, self.ts_width, b' ', |mut buf| {
if ts
.as_rfc3339()
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod input;
pub mod output;
pub mod settings;
pub mod theme;
pub mod timeparse;
pub mod timestamp;
pub mod types;

Expand Down
Loading

0 comments on commit cebba1e

Please sign in to comment.