简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM