https://github.com/flowerinthenight/pretty
A simple JSON log prettifier tool.
https://github.com/flowerinthenight/pretty
go golang json prettifier pretty-print stderr stdout
Last synced: 5 months ago
JSON representation
A simple JSON log prettifier tool.
- Host: GitHub
- URL: https://github.com/flowerinthenight/pretty
- Owner: flowerinthenight
- License: mit
- Created: 2018-05-11T05:07:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-12T19:21:05.000Z (over 7 years ago)
- Last Synced: 2024-06-20T12:39:17.327Z (over 1 year ago)
- Topics: go, golang, json, prettifier, pretty-print, stderr, stdout
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Overview
`pretty` is a simple wrapper tool that prettifies a process's stdout/stderr's JSON output line by line. If output line is not a valid JSON, or does not contain a valid JSON, it will just print the line as is. It also works in "follow" mode, such as `tail -f ...` or `kubectl logs -f ...`.
It also works with https://github.com/wercker/stern (which I use a lot), that is, the JSON log has a text prefix (pod name in `stern`'s case). It will print the text prefix first, then append the prettified JSON. To enable color for `stern`, you can try the following command:
```bash
$ pretty --stern=true -- stern -s 24h
```Example: (normal JSON logs using logrus, redacted)
```bash
$ kubectl logs -f svc-699544fd4d-zzlcf
...
{"action":"describe-deployments","http_method":"GET","level":"info","service":"stack","time":"..."...}
{"context":"metrics-middleware","http_method": "GET","level":"info","service":"stack","time":"..."...}
{"action": "encode-response","http_method": "GET","level": "info","msg": "marshal response as is"...}
...
```Example: (wrapped by pretty, redacted)
```bash
$ pretty -- kubectl logs -f svc-699544fd4d-zzlcf
...
2018/05/11 14:58:45 [stdout] {
"action": "describe-deployments",
"http_method": "GET",
"level": "info",
"msg": "describe={Type:compute.v1.instance Zone:asia-northeast1-a Name:...}",
"request": "92b86ab1-7c8e-4f77-871a-7caf132b421e",
"service": "stack",
"time": "2018-05-11T05:58:45Z"
}
2018/05/11 14:58:45 [stdout] {
"context": "metrics-middleware",
"http_method": "GET",
"level": "info",
"msg": "fn=DescribeDeployment, duration=1.561291986s",
"request": "92b86ab1-7c8e-4f77-871a-7caf132b421e",
"service": "stack",
"time": "2018-05-11T05:58:45Z"
}
2018/05/11 14:58:45 [stdout] {
"action": "encode-response",
"http_method": "GET",
"level": "info",
"msg": "marshal response as is",
"request": "92b86ab1-7c8e-4f77-871a-7caf132b421e",
"time": "2018-05-11T05:58:45Z"
}
...
```## Installation
```bash
$ go get -u -v github.com/flowerinthenight/pretty
```## Usage
You can prepend the command that you want to prettify with `pretty [flags] --`. The double-dash will ensure that any succeeding flags belong to the wrapped command, not to `pretty`.
```bash
$ pretty -- kubectl logs -f svc-699544fd4d-zzlcf
```