I'm deploying a Cloud Function with the python37
runtime. Thanks to this question I know that I can hook up the Python native logger to Stackdriver logging. So my Cloud Function looks like this:
import logging
logging.basicConfig(format="%(module)s.%(funcName)s: %(message)s", level=logging.INFO)
from google.cloud import logging as glogging
glogging.Client().setup_logging()
def endpoint():
logging.info("this should be prefixed with main.endpoint")
return "ok"
But when I review the resulting logs in Stackdriver:
- They're ignoring my formatting, which doesn't happen locally.
- Each log appears twice: once at its defined severity, and a second time at
ERROR
severity.
It seems that something in google-cloud-logging
is only processing the message and ignoring everything else. Is there a way to pass it the formatter I defined?
And why are the logs duplicated?