0
votes

When logging from a module logger inside Google Cloud Functions the logs are not stored in Google Cloud Logging when the Cloud Function is invoked. The logger from the Python logging module uses the integration with Google Cloud Logging as shown here.

I have created a sample code to illustrate this behaviour. The main.py file is the following:

import logging
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler


client = google.cloud.logging.Client()
handler = CloudLoggingHandler(client, name='module_logger_log')
module_logger = logging.getLogger('module_logger')
module_logger.setLevel(logging.DEBUG)
module_logger.addHandler(handler)
module_logger.info('log info: module_logger created')


def cf_endpoint(req):
    # Testing all severities
    module_logger.debug('log debug')
    module_logger.info('log info')
    module_logger.warning('log warning')
    module_logger.error('log error')
    module_logger.critical('log critical')

    return 'ok'

The deployment is HTTP triggered, uses Python 3.8, the entry point is the function cf_endpoint and the requirements.txt file is the following:

google-cloud-logging==2.0.2

The logs stored in Google Cloud Logging from the deployment and triggering of the code can be found here. As it can be appreciated the log from the deployment appears, but the logs from the entry point are not present.

Has anyone experienced this kind of buggy behaviour or am I overlooking something?

Thanks in advance.

1

1 Answers

0
votes

It would be best to open an Issue Tracker as that would allow GCP support to pass this on to the appropriate teams in order to fix this issue.