4

I am trying to write logs while using python on google app engine flexible environment.

I want to use the default python logging library and use a handler for logging. This is my code:

import logging
import google.cloud.logging # Don't conflict with standard logging
from google.cloud.logging.handlers import CloudLoggingHandler,setup_logging
client = google.cloud.logging.Client(app.config['PROJECT_ID'])
handler = CloudLoggingHandler(client)
# Attaches the handler to the root logger
setup_logging(handler)
logging.info("blabla")

It just doesn't work, I can't find the logs in stackdriver logging. I tryed writing the logs without an handler like this:

from google.cloud import logging
client = logging.Client()
logger = client.logger('log_name')
logger.log_text("blabla")

Also, doesn't work.

I also tryed to write the logs to stdout but I don't have the option to select it in stackdriver logging.

Everything worked fine when I used the standard environment..

Lee
  • 781
  • 2
  • 11
  • 31
  • flexible vm logging seems to work different from standard app engine. Filtering the logs to `app` or `stdout` , not just `request_log` seems to work for me. Also checkout this answer http://stackoverflow.com/a/36921823/2987899 – atimothee Nov 28 '16 at 07:21
  • How do you write the logs? using the python's standard logging library? or using the code that I added above? – Lee Nov 28 '16 at 10:06

1 Answers1

1

It works if you use the following:

import logging
logging.basicConfig(level=logging.DEBUG) #change this to whatever log level you want.

Then in code you can use the normal appengine style logging:

logging.debug("Hello")

In the logs viewer, select GAE Application and stderr stdout.

DEBUG:root:Hello
Rob Curtis
  • 2,245
  • 24
  • 33