2

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:

  1. They're ignoring my formatting, which doesn't happen locally.
  2. 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?

helgridly
  • 133
  • 8
  • Are you using the pyhton logging library, or the stackdriver logging library from [here](https://cloud.google.com/logging/docs/api/tasks/creating-logs#writing_log_entries)? I ask because the declaration of severity looks a bit different in your code. – rsalinas Nov 21 '19 at 11:24

1 Answers1

0

When I ran the code locally, I got this:

main.endpoint: this should be prefixed with main.endpoint
this should be prefixed with main.endpoint
Waiting up to 5 seconds.
Sent all pending logs.

So, it seems that the library is duplicating logs.

Yuri Grinshteyn
  • 727
  • 3
  • 13