结合尾巴-F和json [英] Combine tail -F and json

查看:69
本文介绍了结合尾巴-F和json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日志文件每行有一个json对象. 我使用[json] [1]通过以下方式获取人类可读的输出:

My log files have one json object per line. I use [json][1] to get a human readable output via

cat mylog.log | json -a field1 field2

现在我想拥有

tail -F mylog.log | json -a field1 field2

用于连续输出.但这似乎不是 工作时,外壳只是挂了.如果我使用&| 避免缓冲问题,输出就像 我只运行cat.

for a continuous output. But this seems not to work, the shell simply hangs. If I use &| to avoid buffering issues, the output is as if I only run cat.

mylog.log看起来像这样:

{"field1": entry1a, "field2": entry2a, "field3": entry3a}
{"field1": entry1b, "field2": entry2b, "field3": entry3b}

有什么建议吗?

[1] https://github.com/trentm/json

推荐答案

它看起来像json

It's looks like json first loads the whole stdin into a buffer and only then processes the data, but you should still be able to achieve stream processing by calling it for each of the lines added to the log file, something like this:

tail -F mylog.log | while read line; do echo "$line" | json -a field1 field2; done

这篇关于结合尾巴-F和json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆