Search code examples
google-app-enginegoogle-cloud-platformstackdrivergoogle-cloud-tasks

No logs available for google cloud tasks?


I have a very basic Flask app set up in a Google App Engine:

from flask import Flask
app = Flask(__name__)

@app.route("/<id>")
def hello(id):
    print("Got this id: {}".format(id))
    return "Hello World: {}".format(id)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8080, debug=True)

I have enabled logging by running this in my terminal: gcloud beta tasks queues update [QUEUE_ID] --log-sampling-ratio=1.0

I am intentionally triggering an error by adding a POST request to my Flask endpoint. I see in my queue that this task retries many times, but when I click on the logs, I see this (task name and queue name intentionally modified for this screenshot): enter image description here

I am expecting to see the error that I get from gcloud app logs read, which is: 2019-11-18 16:27:59 default[20191118t002408] "POST /example_task_handler" 405

What am I doing wrong?

Update: I do see the logs I am looking for in the Google App Engine logs, but I don't see anything when I click on the logs for the individual failing POST Request task that gets retried.


Solution

  • It turns out the issue was twofold.

    1. I needed to use the python logging library, so I switched to logging.info('Got this id: {}'.format(id))
    2. The default logging for python is warning and higher, so I needed to specify that it should print everything, which I did with:
    logging.basicConfig()
    logging.getLogger().setLevel(logging.DEBUG)
    

    (this works because DEBUG is the lowest logging level).