Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "json-lines-viewer"
version = "0.4.3"
version = "0.4.4"
edition = "2024"
description = "JSON Lines Viewer - Terminal-UI to view application logs in 'Json line format' or Zip files containing such files"
description = "JSON Lines Viewer - Terminal-UI to view JSON line files (e.g. application logs) or Zip files containing such files"
documentation = "https://github.com/bitmagier/json-lines-viewer"
authors = ["Roman Krüger"]
keywords = ["Json", "viewer", "TUI"]
keywords = ["JSON", "viewer", "TUI"]
license = "MIT"
repository = "https://github.com/bitmagier/json-lines-viewer"

Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
JSON Lines Viewer
---
A terminal-UI to browse through JSON-line files.
Terminal-UI to view JSON line files (e.g. application logs) or Zip files containing such files

_The main use case is to support the analysis of comprehensive application logs in 'Json line' format._

Expand All @@ -17,11 +17,11 @@ Download precompiled binary for your platform from Github.
## Usage

```
JSON Lines Viewer - Terminal-UI to view application logs in 'Json line format' or Zip files containing such files.
JSON Lines Viewer - Terminal-UI to view '.json' line files (e.g. application logs) or Zip files containing such files

Navigation: Cursor keys, PageUp/Down, Enter/Esc.
Find content: Ctrl-f or '/' and navigate to next/previous finding via cursor Down/Up.
Save current settings: Ctrl-s (e.g. field order. Settings come from commandline arguments and a previously saved config file)
Search content: Ctrl-f or '/' and navigate to next/previous finding via cursor down/up. Leave search field with `Esc`.
Save current settings: Ctrl-s (Settings may come from commandline options and a previously saved config file)

Usage: json-lines-viewer [OPTIONS] [FILES]...

Expand All @@ -38,14 +38,16 @@ Options:

-h, --help
Print help (see a summary with '-h')

-V, --version
Print version
```

### Example
```
json-lines-viewer --field-order @timestamp,level,application_id,message,application_version,land,host_ipv4,host_name,thread_name,correlation_id,logger_name logs-export-XXXX.zip
json-lines-viewer --field-order @timestamp,level,application_id,message,application_version,land,host_ipv4,host_name,thread_name,correlation_id,logger_name logs-export-xxxxx.zip
```


## Program navigation / usage

- Use Cursor Keys and PageUp/PageDown to navigate on a page
Expand Down
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::io::BufRead;
use std::path::{Path, PathBuf};

#[derive(Parser, Debug)]
#[command(version, about, long_about = Some("JSON Lines Viewer - Terminal-UI to view application logs in 'Json line format' or Zip files containing such files.\n\
\n\
Navigation: Cursor keys, PageUp/Down, Enter/Esc.\n\
Search content: Ctrl-f or '/' and navigate to next/previous finding via cursor Down/Up.\n\
Save current settings: Ctrl-s (e.g. field order. Settings come from commandline arguments and a previously saved config file)"))]
#[command(version, about, long_about = Some("JSON Lines Viewer - Terminal-UI to view JSON line files (e.g. application logs) or Zip files containing such files\n\
\n\
Navigation: Cursor keys, PageUp/Down, Enter/Esc.\n\
Search content: Ctrl-f or '/' and navigate to next/previous finding via cursor down/up. Leave search field with `Esc`.\n\
Save current settings: Ctrl-s (Settings may come from commandline options and a previously saved config file)"))]
struct Args {
/// JSON line input files - `.json` or `.zip` files(s) containing `.json` files
files: Vec<PathBuf>,
Expand Down Expand Up @@ -98,7 +98,11 @@ fn load_files(files: &[PathBuf]) -> anyhow::Result<RawJsonLines> {
let mut raw_lines = RawJsonLines::default();

for path in files {
match path.extension().and_then(|e| e.to_str()) {
match path.extension()
.and_then(|e| e.to_str())
.map(|e| e.to_ascii_lowercase())
.as_deref()
{
Some("json") => load_lines_from_json(&mut raw_lines, path).with_context(|| format!("failed to load lines from {path:?}"))?,
Some("zip") => load_lines_from_zip(&mut raw_lines, path).with_context(|| format!("failed to load lines from {path:?}"))?,
_ => eprintln!("unknown file extension: '{}'", path.to_string_lossy()),
Expand Down Expand Up @@ -142,7 +146,7 @@ fn load_lines_from_zip(
.by_index(i)
.with_context(|| format!("failed to get file with index {i} from zip"))?;

if !f.is_file() || !f.name().ends_with(".json") {
if !f.is_file() || !f.name().to_ascii_lowercase().ends_with(".json") {
continue;
}

Expand Down