Tail a log using gloud logging read?
Asked Answered
C

4

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.

Contrabass answered 19/11, 2018 at 8:37 Comment(0)
T
9

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:

Thoracoplasty answered 11/11, 2020 at 5:8 Comment(0)
K
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.

K2 answered 23/11, 2018 at 19:11 Comment(0)
C
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
Clipper answered 15/1, 2020 at 2:30 Comment(0)
M
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

Madelenemadelin answered 20/1, 2021 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.