5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSON形式のtailfみたいなログストリームをjqで表示する

5
Last updated at Posted at 2019-12-26

ログファイルをtail -fやdocker logs -fで見たりする事ありますよね。もし、そのログファイルがjsonフォーマットだったら各ログ毎にjqしたものを見たいですよね。

logs.sh
docker logs --tail 10 -f greatapp | while read line
do
  echo "$line" | jq -R -r '. as $line | try fromjson catch $line'
done

これがその答えです。

see also

How to skip non-json lines?
https://github.com/stedolan/jq/issues/884

𝑸: Is there a way to have jq keep going after it hits an error in the input file? Can jq handle broken JSON?
https://github.com/stedolan/jq/wiki/FAQ#general-questions

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?