Skip to content

Commit f4da0af

Browse files
authored
Improve readme file (#27)
* Introduction * Key Features * Installation * Usage * Configuration * Command-Line Arguments * k9s Plugin * Development * License
1 parent 6135ba8 commit f4da0af

File tree

1 file changed

+242
-26
lines changed

1 file changed

+242
-26
lines changed

README.md

Lines changed: 242 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,213 @@
11
# json-log-viewer
22

3-
[![Maven Central](https://img.shields.io/maven-central/v/ru.d10xa/json-log-viewer_2.12.svg?label=Maven%20Central%20(Scala%202.12))](https://search.maven.org/artifact/ru.d10xa/json-log-viewer_2.12)
43
[![Maven Central](https://img.shields.io/maven-central/v/ru.d10xa/json-log-viewer_3.svg?label=Maven%20Central%20(Scala%203))](https://search.maven.org/artifact/ru.d10xa/json-log-viewer_3)
54

5+
## Introduction
66

7-
The `json-log-viewer` converts JSON logs to a human-readable
8-
format via stdin and offers a Scala.js browser version,
9-
streamlining log analysis for developers and system administrators.
7+
`json-log-viewer` is a versatile tool designed to simplify the analysis
8+
of JSON logs for developers and system administrators.
9+
Whether you work in the command line or prefer a browser-based interface,
10+
`json-log-viewer` provides powerful features for filtering, combining, and visualizing log streams.
1011

11-
[DEMO](https://d10xa.ru/json-log-viewer/)
12+
The primary goal of `json-log-viewer` is to transform raw JSON logs into a human-readable format,
13+
making them significantly easier to interpret and process.
14+
With support for advanced filtering, dynamic configuration updates, multi-source input,
15+
and streamlined configuration management,
16+
this tool offers a comprehensive solution for log analysis across various environments.
1217

13-
![screenshot.png](screenshot.png)
18+
You can also try the browser-based version online: [DEMO](https://your-demo-url.com).
1419

15-
## install
20+
### Example Output
21+
Below is an example of formatted JSON logs in the command-line interface:
1622

17-
```
23+
![Example Output](screenshot.png)
24+
25+
## Key Features
26+
27+
- **Human-Readable Log Output**
28+
Effortlessly transform raw JSON logs into a structured, easy-to-read format.
29+
30+
- **Flexible Interfaces**
31+
Use the command-line utility or a browser-based application for visualization.
32+
33+
- **Multi-Source Input**
34+
Combine the outputs of multiple commands into a single unified log stream.
35+
36+
- **Advanced Filtering**
37+
- Apply regular expressions to extract relevant log entries.
38+
- Use SQL-like queries to filter and query JSON fields.
39+
40+
- **YAML Configuration**
41+
Define input streams and configurations using YAML files.
42+
43+
- **Dynamic Configuration Updates**
44+
Hot-reload filters and configurations without restarting the tool.
45+
46+
- **stdin Support**
47+
Process logs directly from the standard input for real-time analysis.
48+
49+
- **Integration with k9s**
50+
Seamlessly integrate with the k9s Kubernetes CLI tool to visualize logs directly within k9s.
51+
52+
## Installation
53+
54+
### Requirements
55+
56+
- **Coursier** (for installation and dependency management)
57+
58+
### Install with Coursier
59+
60+
Install `json-log-viewer` globally using `coursier`:
61+
62+
```bash
1863
coursier install json-log-viewer --channel https://git.io/JvV0g
1964
```
2065

21-
## build jvm version
66+
After installation, ensure the tool is available:
2267

23-
```
24-
sbt stage
68+
```bash
69+
json-log-viewer --help
2570
```
2671

27-
## run jvm version
72+
## Usage
2873

29-
```
30-
cat log.txt | ./json-log-viewer/jvm/target/universal/stage/bin/json-log-viewer
31-
```
74+
### Quick Start
75+
1. Install `json-log-viewer` using Coursier.
76+
2. Pass logs to the tool via stdin:
77+
```bash
78+
cat log.txt | json-log-viewer
79+
```
80+
3. Apply filters directly from the command line:
81+
```bash
82+
cat log.txt | json-log-viewer --filter "level = 'ERROR'"
83+
```
3284

33-
## build js version
85+
### SQL Filtering
3486

35-
```
36-
sbt fullLinkJS
37-
```
87+
`json-log-viewer` supports SQL-like filtering for JSON fields, allowing precise log analysis.
88+
You can use comparison and logical operations.
89+
90+
#### Supported Syntax
91+
- **Comparison operators**:
92+
- `=`: Equal
93+
- `!=`: Not equal
94+
- `LIKE`: Matches with patterns (`%` for wildcard)
95+
- `NOT LIKE`: Negates pattern matching
96+
- **Logical operators**:
97+
- `AND`: Logical AND
98+
- `OR`: Logical OR
99+
- `()` for grouping expressions
100+
- **Literals and Identifiers**:
101+
- Identifiers represent JSON keys (e.g., `level`).
102+
- Literals are strings enclosed in single quotes (e.g., `'ERROR'`).
103+
104+
#### Examples
105+
106+
1. Filter logs where `level` is `'ERROR'`:
107+
```bash
108+
cat log.txt | json-log-viewer --filter "level = 'ERROR'"
109+
```
110+
2. Match logs where message contains the word "timeout":
111+
```bash
112+
cat log.txt | json-log-viewer --filter "message LIKE '%timeout%'"
113+
```
114+
3. Combine conditions:
115+
```bash
116+
cat log.txt | json-log-viewer --filter "level = 'ERROR' AND message LIKE '%timeout%'"
117+
```
118+
4. Exclude logs with specific patterns:
119+
```bash
120+
cat log.txt | json-log-viewer --filter "message NOT LIKE '%timeout%'"
121+
```
122+
5. Group conditions with parentheses:
123+
```bash
124+
cat log.txt | json-log-viewer --filter "(level = 'ERROR' OR level = 'WARN') AND message LIKE '%connection%'"
125+
```
126+
127+
## Configuration
128+
129+
`json-log-viewer` supports defining input streams, filters, and other settings using a YAML configuration file.
130+
131+
### YAML Configuration Structure
38132

39-
## run js version
133+
A configuration file consists of one or more **feeds**.
134+
Each feed represents a log source and can have the following attributes:
135+
- **name** (optional): A descriptive name for the feed.
136+
- **commands** (required): A list of shell commands that produce log output.
137+
- **inlineInput** (optional): Direct input as a string instead of executing commands.
138+
- **filter** (optional): SQL-like filter expression for processing logs (e.g., `level = 'ERROR'`).
139+
- **formatIn** (optional): Input log format. Supported values:
140+
- `json` (default).
141+
- `logfmt`.
142+
- **rawInclude** and **rawExclude** (optional): Lists of regular expressions to include or exclude from processing.
40143

144+
### Example Configuration File
145+
146+
```yaml
147+
feeds:
148+
- name: "application-1-logs"
149+
commands:
150+
- cat log1.txt
151+
filter: |
152+
level = 'ERROR' AND message LIKE '%timeout%'
153+
formatIn: json
154+
rawInclude:
155+
- "ERROR"
156+
rawExclude:
157+
- "DEBUG"
158+
- name: "application-2-logs"
159+
commands:
160+
- cat log2.txt
161+
filter: |
162+
message NOT LIKE '%heartbeat%'
163+
formatIn: logfmt
41164
```
42-
cat log.txt | node ./json-log-viewer/js/target/scala-3.3.1/json-log-viewer-opt/main.js
165+
166+
#### Running with a Configuration File
167+
168+
To use a YAML configuration file, pass its path with the --config-file option:
169+
170+
```bash
171+
json-log-viewer --config-file json-log-viewer.yml
43172
```
44173

45-
# frontend-laminar
174+
## Command-Line Arguments
175+
176+
`json-log-viewer` also supports direct configuration via command-line arguments:
177+
178+
### Supported Options
46179

47-
```~fastLinkJS::webpack```
180+
- **--filter**: Apply SQL-like filters directly to logs.
181+
```bash
182+
cat log.txt | json-log-viewer --filter "level = 'ERROR'"
183+
```
48184

49-
# k9s plugin
185+
- **--config-file**: Specify the path to a YAML configuration file.
186+
```bash
187+
cat log.txt | json-log-viewer --config-file json-log-viewer.yml
188+
```
189+
190+
- **--format-in**: Specify the input log format (supported formats: json, logfmt).
191+
```bash
192+
cat log.txt | json-log-viewer --format-in logfmt
193+
```
194+
195+
- **--format-out**: Specify the output format (supported formats: pretty, raw).
196+
```bash
197+
cat log.txt | json-log-viewer --format-out raw
198+
```
199+
200+
- **--timestamp-after** and **--timestamp-before**: Filter logs by a specific time range.
201+
```bash
202+
cat log.txt | json-log-viewer --timestamp-after 2024-01-01T00:00:00Z --timestamp-before 2024-01-31T23:59:59Z
203+
```
204+
205+
- **--timestamp-field**: Specify the field name for timestamps (default: @timestamp).
206+
```bash
207+
json-log-viewer --timestamp-field time
208+
```
209+
210+
## k9s Plugin
50211

51212
Integrate json-log-viewer with k9s to view formatted JSON logs directly within the k9s interface.
52213

@@ -56,7 +217,7 @@ For the plugin to work correctly, the following must be installed on your system
56217
2. **json-log-viewer** (optional) - If already installed, the plugin will use it directly; otherwise, it will fall back to using `coursier` to launch it.
57218

58219
### Installation
59-
Add the following to your k9s plugin file
220+
Add the following to your k9s plugin file
60221
(usually located at ~/.k9s/plugins.yaml or, on macOS, check the plugin path with `k9s info`):
61222

62223
```yaml
@@ -85,9 +246,64 @@ plugins:
85246
fi
86247
```
87248
88-
## k9s plugin usage
249+
### k9s plugin usage
89250
90251
1. Install json-log-viewer
91252
2. Launch k9s
92253
3. Select a Pod or Container
93254
4. Press Ctrl+L to view logs formatted by json-log-viewer
255+
256+
257+
## Development
258+
259+
This section provides instructions for building and running
260+
both the JVM and JavaScript versions of `json-log-viewer`.
261+
It also includes notes for working on the `frontend-laminar` module.
262+
263+
### Prerequisites
264+
Ensure you have the following installed on your system:
265+
- Java 11+ (for building the JVM version)
266+
- Node.js 23+ (for building the JS version)
267+
- sbt (Scala Build Tool)
268+
269+
### Building the JVM Version
270+
To build the JVM version of the project, use the command:
271+
272+
```bash
273+
sbt stage
274+
```
275+
276+
This compiles the code and prepares the executable under the `jvm/target/universal/stage/bin/` directory.
277+
278+
### Running the JVM Version
279+
Run the application with:
280+
```bash
281+
cat log.txt | ./json-log-viewer/jvm/target/universal/stage/bin/json-log-viewer
282+
```
283+
284+
Replace `log.txt` with the path to your JSON log file. The output will be displayed in a human-readable format.
285+
286+
### Building the JavaScript Version
287+
288+
To build the JavaScript version, you can use one of the following options:
289+
290+
1. **Optimized Build**: Use the command:
291+
```bash
292+
sbt fullLinkJS
293+
```
294+
This generates a production-ready JavaScript file located at:
295+
`frontend-laminar/target/scala-3.6.2/frontend-laminar-opt/main.js`
296+
2. **Fast Development Build**: Use the command:
297+
```bash
298+
sbt fastLinkJS
299+
```
300+
This generates a faster, less optimized build located at:
301+
`frontend-laminar/target/scala-3.6.2/frontend-laminar-fastopt/main.js`
302+
303+
Choose the appropriate option based on your needs:
304+
- Use `fullLinkJS` for production or when you need a fully optimized bundle.
305+
- Use `fastLinkJS` for local development with faster build times.
306+
307+
## License
308+
309+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for full details.

0 commit comments

Comments
 (0)