sgarg
sgarg

Reputation: 2459

How do I run jq on each log line and tail it?

I have a log file with each line being a json object. I want to view the log lines as pretty json while being able to tail the logs, with maybe tail or less. I have tried the following and they either return immediately i.e. don't tail the logs, or appear to tail (by not returning) but don't update with new logs

less jsonlines.log | jq "." 
tail -f jsonlines.log | jq "."

Upvotes: 6

Views: 7009

Answers (1)

glenn jackman
glenn jackman

Reputation: 246837

"Works for me"™:

  • in one terminal window:

    while true; do echo "{\"date\":\"$(date)\"}" >> logfile; sleep 1; done
    
  • in another:

    tail -f logfile | jq .
    

Upvotes: 11

Related Questions