1

Stack: Google App Engine Flexible Python 2.7

I cannot seem to write info messages using the python logging module after configuring it to use stackdriver. In my main function for my service I have:

from paste import httpserver
import google.cloud.logging

client = google.cloud.logging.Client('my-project-id')
client.setup_logging(logging.INFO)
logging.getLogger().setLevel(logging.INFO)
logging.info('in main - info')
httpserver.serve(app, host='127.0.0.1', port='8080')

But I do not see the text 'in main - info' in my stackdriver logs. I also have the following code that responds to a request for the main page of my app:

class MainPage(webapp2.RequestHandler):
  def get(self):
    logging.info('in MainPage - info')
    logging.error('in MainPage - error')
    print('in MainPage - print')
    self.response.write('nothing to see.')

This code returns 'noting to see' to the browser, and writes 'in MainPage - error' to the stackdriver logs via stderr, as well as 'in MainPage - print' to the stackdriver logs via stdout. however, 'in MainPage - info' does not appear anywhere in the stackdriver logs. It is as if setting the log level of the logger has no effect and it is stuck at ERROR.

I've tried many variations of this and searched for examples but am coming up empty. I am sure there must be something I am missing regarding the use of stackdriver logging - I'm hoping someone can point me to an example that successfully writes info log messages to stackdriver using python 2.7 and google app engine flexible.

Thanks in advance!

  • could you provide a [Minimal Verifiable Example](https://stackoverflow.com/help/mcve)? So far I couldn't replicate your issue and your example also doesn't work. – A.Queue Jun 15 '18 at 09:54

0 Answers0