6

Is it not possible to watch the tail of a particular log on the terminal command line using gcloud logging read command? I'm looking for something akin to the well known tail -f invocation on standard linux. I can't find any documented parameter which allows it. The web console provides a play button feature which does exactly this, but when I leave it running for more than 10 minutes the whole tab becomes unresponsive and it feels like it will crash the whole browser.

I've got a decent log filter that I want to "watch" on my terminal, and not in my Chrome browser. However the watch command doesn't read output from gcloud command, it just sits there when I try the watch -n 30 gcloud logging read ... invocation.

Thoughts, suggestions are most welcome.

Dhiraj Gupta
  • 9,704
  • 8
  • 49
  • 54

4 Answers4

7

You can now live tail logs using gcloud alpha logging tail command. This is a low-latency streaming API to tail your logs directly from Logging. You can learn more in the following pages:

Summit Raj
  • 820
  • 5
  • 10
1

"watch -n 30 gcloud logging read" does work in my cloud shell. However, "tail" does not work on 'gcloud logging read'.

The play button you mentioned updates/refreshes just fine (I've tested for over half-an-hour). Try incognito window.

Asif Tanwir
  • 119
  • 6
1

Since gcloud logging read supports timestamp filter, it is possible to call that command in a loop requesting more recent chunk of data in each call. Something like this:

CURRENT_DATE_UTC=`date --utc -Iseconds`
while true; do
  sleep 60
  echo "logs since ${CURRENT_DATE_UTC}"
  gcloud logging read "<your filter here> timestamp>=\"${CURRENT_DATE_UTC}\" ... > logfile.txt
  cat logfile.txt | sed '/^$/d'
  if [[ $(cat logfile.txt | head -n 5 | wc -l) -ne 0 ]]; then
    CURRENT_DATE_UTC=`date --utc -Iseconds`;
  fi
done
Aleksey Vlasenko
  • 990
  • 9
  • 10
1

Logging has added live tailing now to the product

https://cloud.google.com/blog/products/management-tools/cloud-logging-gets-real-time-log-searching

ptone
  • 884
  • 7
  • 5