Skip to content

Commit 72e83b2

Browse files
authored
feat: initial implementation (#1)
1 parent 52712f3 commit 72e83b2

34 files changed

+1696
-0
lines changed

.github/dependabot.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"
8+
commit-message:
9+
prefix: "chore(gha)"
10+
pull-request-branch-name:
11+
separator: "/"
12+
13+
- package-ecosystem: "gomod"
14+
directory: "/"
15+
schedule:
16+
interval: "monthly"
17+
commit-message:
18+
prefix: "chore(gomod)"
19+
pull-request-branch-name:
20+
separator: "/"

.github/workflows/check.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: check-json-log-viewer
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: '1.20.6'
18+
id: go
19+
20+
- name: Check out code into the Go module directory
21+
uses: actions/checkout@v3
22+
23+
- name: Build
24+
run: make build
25+
26+
- name: Lint
27+
run: make lint
28+
29+
- name: Test
30+
run: make test
31+
32+
- uses: shogo82148/actions-goveralls@v1
33+
with:
34+
path-to-profile: coverage.out

.github/workflows/release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: release-json-log-viewer
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
goreleaser:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version: '1.20.6'
19+
20+
- name: Run GoReleaser
21+
uses: goreleaser/goreleaser-action@v4
22+
with:
23+
version: latest
24+
args: release --rm-dist
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

.github/workflows/semantic.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: check-pr-semantic
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
main:
9+
name: Validate PR title
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: amannn/action-semantic-pull-request@v5
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
bin
8+
9+
# IDE
10+
.vscode
11+
12+
# Test binary, built with `go test -c`
13+
*.test
14+
15+
# Output of the go coverage tool, specifically when used with LiteIDE
16+
*.out
17+
18+
# Dependency directories (remove the comment below to include it)
19+
vendor/

.golangci.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"linters": {
3+
"enable-all": true,
4+
"disable": [
5+
"lll",
6+
"gochecknoglobals",
7+
"bodyclose",
8+
"wsl",
9+
"funlen",
10+
"maligned",
11+
"exhaustivestruct",
12+
"gci",
13+
"wrapcheck",
14+
"varnamelen",
15+
"testpackage",
16+
"exhaustive",
17+
"gomnd",
18+
"thelper",
19+
"paralleltest",
20+
"tagliatelle",
21+
"scopelint",
22+
"golint",
23+
"interfacer",
24+
"nonamedreturns",
25+
"exhaustruct",
26+
"nolintlint",
27+
"deadcode",
28+
"wastedassign",
29+
"structcheck",
30+
"varcheck",
31+
"ifshort",
32+
"nosnakecase",
33+
"rowserrcheck",
34+
"depguard",
35+
"ireturn",
36+
"gomoddirectives"
37+
]
38+
},
39+
"linters-settings": {
40+
"goimports": {
41+
"local-prefixes": "github.com/hedhyw/json-log-viewer/"
42+
},
43+
"revive": {}
44+
}
45+
}

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
GOLANG_CI_LINT_VER:=v1.53.3
2+
OUT_BIN?=${PWD}/bin/jlv
3+
COVER_PACKAGES=./...
4+
VERSION?=${shell git describe --tags}
5+
6+
run:
7+
@echo "building ${VERSION}"
8+
go run ./cmd/jlv assets/example.log
9+
.PHONY: build
10+
11+
build:
12+
@echo "building ${VERSION}"
13+
go build \
14+
-o ${OUT_BIN} \
15+
--ldflags "-s -w -X main.version=${VERSION}" \
16+
./cmd/jlv
17+
.PHONY: build
18+
19+
install:
20+
go install ./cmd/jlv
21+
.PHONY: install
22+
23+
lint: bin/golangci-lint
24+
./bin/golangci-lint run
25+
.PHONY: lint
26+
27+
test:
28+
go test \
29+
-coverpkg=${COVER_PACKAGES} \
30+
-covermode=count \
31+
-coverprofile=coverage.out \
32+
./...
33+
go tool cover -func=coverage.out
34+
.PHONY: test
35+
36+
vendor:
37+
go mod tidy
38+
go mod vendor
39+
.PHONY: vendor
40+
41+
bin/golangci-lint:
42+
curl \
43+
-sSfL \
44+
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
45+
| sh -s $(GOLANG_CI_LINT_VER)

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# JSON Log Viewer
2+
3+
![Version](https://img.shields.io/github/v/tag/hedhyw/json-log-viewer)
4+
![Build Status](https://github.com/hedhyw/json-log-viewer/actions/workflows/check.yml/badge.svg)
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/hedhyw/json-log-viewer)](https://goreportcard.com/report/github.com/hedhyw/json-log-viewer)
6+
[![Coverage Status](https://coveralls.io/repos/github/hedhyw/json-log-viewer/badge.svg?branch=main)](https://coveralls.io/github/hedhyw/json-log-viewer?branch=main)
7+
8+
It is an interactive tool for viewing and analyzing complex log files with structured JSON logs.
9+
10+
![Animation](./assets/animation.webp)
11+
12+
Main features:
13+
1. It is interactive.
14+
2. Is shows similified log records.
15+
3. It is possible to see the full prettified JSON after clicking.
16+
4. It includes non-JSON logs as they are.
17+
5. It understands different field names.
18+
6. It supports case-insensitive filtering.
19+
7. It is simple.
20+
21+
It uses [antonmedv/fx](https://github.com/antonmedv/fx) for viewing JSON and [charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea) for terminal UI. The tool is inspired by the project [json-log-viewer](https://github.com/gistia/json-log-viewer) which is unfortunately outdated.
22+
23+
## Table of content
24+
25+
- [JSON Log Viewer](#json-log-viewer)
26+
- [Table of content](#table-of-content)
27+
- [Usage](#usage)
28+
- [Install](#install)
29+
- [MacOS/Linux HomeBrew](#macoslinux-homebrew)
30+
- [Go](#go)
31+
- [Package](#package)
32+
- [Standalone Binary](#standalone-binary)
33+
- [Source](#source)
34+
- [Roadmap](#roadmap)
35+
- [Resources](#resources)
36+
- [License](#license)
37+
38+
39+
## Usage
40+
41+
```sh
42+
jlv file.json
43+
```
44+
45+
| Key | Action |
46+
| ------ | -------------- |
47+
| Enter | Open/Close log |
48+
| F | Filter |
49+
| Ctrl+C | Exit |
50+
| Esc | Back |
51+
| ↑↓ | Navigation |
52+
53+
## Install
54+
55+
### MacOS/Linux HomeBrew
56+
57+
```sh
58+
brew install hedhyw/main/json-log-viewer
59+
```
60+
61+
### Go
62+
63+
```bash
64+
go install github.com/hedhyw/json-log-viewer/cmd/jlv@latest
65+
```
66+
67+
### Package
68+
69+
Latest DEB and RPM packages are available on [the releases page](https://github.com/hedhyw/json-log-viewer/releases/latest).
70+
71+
### Standalone Binary
72+
73+
Download latest archive `*.tar.gz` for your target platform from [the releases page](https://github.com/hedhyw/json-log-viewer/releases/latest) and extract it to `/usr/local/bin/jlv`. Add this path to `PATH` environment.
74+
75+
### Source
76+
77+
```
78+
git clone [email protected]:hedhyw/json-log-viewer.git
79+
cd json-log-viewer
80+
make build
81+
cp ./bin/jlv /usr/local/bin
82+
chmod +x /usr/local/bin/jlv
83+
```
84+
85+
## Roadmap
86+
87+
- Accept stream of logs.
88+
- Add colors to log levels.
89+
- Add a configuration file (similar to `.json-log-viewer`).
90+
- Convert number timestamps.
91+
92+
## Resources
93+
94+
Alternatives:
95+
- [mightyguava/jl](https://github.com/mightyguava/jl) - Pretty Viewer for JSON logs.
96+
- [pamburus/hl](https://github.com/pamburus/hl) - A log viewer that translates JSON logs into human-readable representation.
97+
- [json-log-viewer](https://github.com/gistia/json-log-viewer) - Powerful terminal based viewer for JSON logs using ncurses.
98+
99+
## License
100+
101+
[MIT License](LICENSE).

assets/animation.webp

2.37 MB
Loading

assets/assets.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package assets
2+
3+
import (
4+
_ "embed"
5+
)
6+
7+
//go:embed example.log
8+
var exampleJSONLog []byte
9+
10+
// ExampleJSONLog returns a copy of the file "example.log".
11+
func ExampleJSONLog() []byte {
12+
target := make([]byte, len(exampleJSONLog))
13+
14+
copy(target, exampleJSONLog)
15+
16+
return target
17+
}

0 commit comments

Comments
 (0)