Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gagan-bansal/munia-pretty-json
Convert the JSON log into readable form with command line.
https://github.com/gagan-bansal/munia-pretty-json
formatter javascript json log nodejs table viewer winston
Last synced: about 7 hours ago
JSON representation
Convert the JSON log into readable form with command line.
- Host: GitHub
- URL: https://github.com/gagan-bansal/munia-pretty-json
- Owner: gagan-bansal
- License: mit
- Created: 2021-10-10T02:08:39.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-08T09:11:49.000Z (over 2 years ago)
- Last Synced: 2024-10-14T06:27:57.724Z (about 1 month ago)
- Topics: formatter, javascript, json, log, nodejs, table, viewer, winston
- Language: JavaScript
- Homepage:
- Size: 606 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## munia-pretty-json
Convert the JSON log into readable form with command line. JSON logs can also be viewed as gird/table form on console.
### Installation
```sh
npm install -g munia-pretty-json
```### Example
JSON log records (app-log.json):
```
{"time":"2021-06-09T02:50:22Z","level":"info","message":"Log for pretty JSON","module":"init","hostip":"192.168.0.138","pid":123}
{"time":"2021-06-09T03:27:43Z","level":"warn","message":"Here is warning message","module":"send-message","hostip":"192.168.0.138","pid":123}
```Run the commond **munia-pretty-json** on shell:
```sh
$ munia-pretty-json app-log.json
```This turns the JSON to:
![output](output1.png)
With this tool the main feature is **template** that prettifies easily the JSON. Here is an example of template:
```sh
$ munia-pretty-json --template '{module --color} - {level} - {message}' app-log.json
```![output](output2.png)
### Usage
Usage: munia-pretty-json [options] <json-file>
tail -f <json-file> | munia-pretty-json [options]
node myapp.js | munia-pretty-json [options]Options:
-t, --template ..... template to format the json record
'{key [options]} {key [options]} {...}'
json property (key) names are used to format the template
default template '{time} {level --color} {message}'
-C, --context ...... print number of lines before and after context
-a, --all .......... print formatted json and non json records if true, default true
print only formatted json if false
--error-key .... print full value of error key, default true
--cache ........ read/write arguments from/to cache file './.mpjrc', default true
-g, --grid ......... grid/table view, default false
-d, --debug ........ print json parsing error message, default false
-h, --help ......... help/usage infromation
-v, --version ...... version of this apptemplate options:
-c, --color ........ color the values of this key, default false
-i, --include ...... include records which match the value of key
-e, --exclude ...... exclude records which match the value of key
-f, --filter ....... regular expression to filter the records
-s, --span ......... span as number of characters for the column widh
in grid/table view
-w, --width ........ width of string to be printed
if negative then width is considered backward
--level-key ........ log level key, default 'level',
effective only when used with --color option
it is useful to select defualt colors for levelstemplate special options for specific options:
-l, --level ........ level value, level upto which records to be included,
default 'info'
--level=info is equivenlent to --include=error,warn,info
Note: option only related to level key
-t, --time ......... format the time key value from milli seconds to string
optional tokens can also be given to format the time
example: -t '[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]'
tokens as per dayjs https://day.js.org/docs/en/display/format
Note: option only related to time keytemplate special keys:
REST ............... print rest of the keys and values as a JSON string
(keys which are not part of the template)
example: -t '{level}: {message} {REST}'
--include-keys ..... keys to include in 'REST'
example: -t '{msg} {REST --include-keys=app,pid}'
Note: option only related to 'REST' key
--exclude-keys ..... keys to exclude from 'REST'
example: -t '{msg} {REST --exclude-keys=host,version}'
Note: option only related to 'REST' key## Testing
```shell
npm test
```
## LicenseLicensed under [MIT](./LICENSE).