Lee
Lee

Reputation: 791

Google Cloud App Engine Flexible - Logs are not working

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..

Upvotes: 4

Views: 982

Answers (1)

Rob Curtis
Rob Curtis

Reputation: 2265

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

Upvotes: 1

Related Questions