0

I've been unable to send logs to Google Cloud Logging inside a Cloud Function using the Cloud Logging client library for Python. The function runs without errors but I can't see the logs on Google Cloud.

Is there something I am missing any configuration settings on the Cloud Function?

I created a small Cloud Function, based on Google's Guide, to isolate the problem:

main.py

from flask import Flask
import logging
import google.cloud.logging

client = google.cloud.logging.Client()
client.get_default_handler()
client.setup_logging()

def log_test(request):
    logging.info("info")
    logging.warning("warning")
    logging.error("error")
    return 'OK'

requirements.txt

Flask==1.0.2
google-cloud-logging==2.3.1

Function is deployed with: gcloud functions deploy log_test --runtime python38 --trigger-http --allow-unauthenticated

The function runs without error but the Log Explorer does not show the written logs: Log Explorer

If I run the same code locally with the environment variable GOOGLE_APPLICATION_CREDENTIALS the logs are properly sent.

I also tried creating a logger as https://stackoverflow.com/a/56810898/154618 but got the same behavior.

buzali
  • 802
  • 1
  • 6
  • 12

0 Answers0