I am trying to attach a logging handler to the Python root logger in my cloud function. I am using below code :
import logging
import os
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging
logLabels = {'ServerName' : os.uname().nodename}
logging_client = google.cloud.logging.Client()
handler = CloudLoggingHandler(logging_client,name='my-test-cf',labels=logLabels)
logging.getLogger().setLevel(logging.INFO)
setup_logging(handler, excluded_loggers=('google.cloud', 'google.auth', 'google_auth_httplib2'))
logging.info(f"Starting Execution of My Test CF")
Result is duplicate log entries one with info and other with error
- info -> Starting Execution of My Test CF
- error -> Starting Execution of My Test CF