Mohammad Ranjbar Z
Mohammad Ranjbar Z

Reputation: 1547

Is there a way to show winston log files like we show it in bunyan CLI?

In Bunyan logger we can see the log files like this: tail -f sample.log | bunyan and show the logs colorful and show json objects pretty, but I couldn't find some thinkg like that solution in Winston logger, any body has idea about that?

Upvotes: 3

Views: 2272

Answers (2)

Gagan
Gagan

Reputation: 1343

Similar to winston-log-viewer I had created munia-pretty-json and using it for many projects. You can visualize any json log at console.

npm install -g munia-pretty-json

Your json data (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 command:

munia-pretty-json app-log.json

Or tail the json file:

tail -f app-log.json | munia-pertty-json

Here is readable output on console:

enter image description here

You can format the output with the template. The default template is '{time} {level -c} {message}'

Using template:

munia-pretty-json -t '{module -c} - {level} - {message}' app-log.json

Output:

enter image description here

Upvotes: 2

Mohammad Ranjbar Z
Mohammad Ranjbar Z

Reputation: 1547

I wrote a tiny npm package based on Bunyan CLI for pretty printing winston logs, you can use that in this way:

  • npm i -g winston-log-viewer
  • tail -f logFile.log | winston-log-viewer

Or

  • tail -f logFile.log | npx winston-log-viewer

https://github.com/mohammadranjbarz/winston-log-viewer

enter image description here

Upvotes: 5

Related Questions