[英]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
在Bunyan logger 中,我们可以看到这样的日志文件:
tail -f sample.log | bunyan
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? tail -f sample.log | bunyan
并显示彩色的日志并漂亮地显示 json 对象,但我在Winston记录器中找不到像这样的解决方案的一些想法,任何人对此有想法吗?
I wrote a tiny npm package based on Bunyan CLI for pretty printing winston logs, you can use that in this way:我写了一个基于 Bunyan CLI 的小 npm 包来漂亮地打印 winston 日志,你可以这样使用它:
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 https://github.com/mohammadranjbarz/winston-log-viewer
Similar to winston-log-viewer I had created munia-pretty-json and using it for many projects.与 winston-log-viewer 类似,我创建了munia-pretty-json并将其用于许多项目。 You can visualize any json log at console.
您可以在控制台中可视化任何 json 日志。
npm install -g munia-pretty-json
Your json data (app-log.json)您的 json 数据 (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:或尾部 json 文件:
tail -f app-log.json | munia-pertty-json
Here is readable output on console:这是控制台上的可读输出:
You can format the output with the template.您可以使用模板格式化输出。 The default template is
'{time} {level -c} {message}'
默认模板是
'{time} {level -c} {message}'
Using template:使用模板:
munia-pretty-json -t '{module -c} - {level} - {message}' app-log.json
Output:输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.