1

I'm configuring Python logging in my Google Cloud function.

# Imports the Cloud Logging client library
import google.cloud.logging

# Instantiates a client
logclient = google.cloud.logging.Client()

# Imports Python logging module
import logging

# Retrieves a Cloud Logging handler based on the environment
# you're running in and integrates the handler with the
# Python logging module. By default this captures all logs
# at INFO level and higher
logclient.get_default_handler()
logclient.setup_logging(log_level=logging.INFO)

And this is the logging line:

logging.info(f'Creating invoice for {entity_id}')

There are no other logging lines of code with that message in this Google Cloud function.

The function itself finishes successfully without any errors.

The logs appear successfully when viewed in Google Cloud Console.

However, it is written as two entries, same timestamp etc, only differing in severity:

  1. INFO: which is the correct level I'm logging at
  2. ERROR: why is this appearing?

Screenshot of logs showing the two entries

Perry Ismangil
  • 422
  • 4
  • 15
  • 2
    Can you show us an example of hour you're actually emitting a log message? – Dustin Ingram Sep 17 '20 at 22:58
  • Screenshot of log added – Perry Ismangil Sep 18 '20 at 14:39
  • Can you show us how you're _generating_ those log messages? – Dustin Ingram Sep 18 '20 at 21:20
  • Logging line added to question – Perry Ismangil Sep 18 '20 at 22:17
  • there has to be some other log in the second group, since it's marked as `warning`. What does that one say? – yedpodtrzitko Sep 19 '20 at 01:28
  • There is no other line of code of logging that message except the one I posted on the question. – Perry Ismangil Sep 19 '20 at 08:35
  • Is the 'trace' item a link to a stack trace? What does it say? – rcriii Sep 19 '20 at 17:24
  • @rcriii I don't believe so I didn't setup any traces or anything. And the function ran successfully. I'll edit to make that clear. – Perry Ismangil Sep 20 '20 at 21:49
  • 2
    Hi, it seems that this is a known issue as per this [Stackoverflow post](https://stackoverflow.com/questions/63243824/duplicate-log-entries-google-cloud-logging-on-stackdriver-in-google-cloud-functi). The possible workaround offered would be to utilize the [Cloud Logging client libraries](https://cloud.google.com/functions/docs/monitoring/logging#using_the_logging_api) so as to write logs to Cloud Logging. Also, I recommend you raise Public Issue Tracker mentioning this issue – Andie Vanille Sep 21 '20 at 16:20
  • Does this answer your question? [Duplicate log entries google cloud logging on stackdriver in google cloud function using python](https://stackoverflow.com/questions/63243824/duplicate-log-entries-google-cloud-logging-on-stackdriver-in-google-cloud-functi) – yedpodtrzitko Sep 21 '20 at 16:29

0 Answers0