Reputation: 110093
I am trying to do the following to connect with stackdriver to my google account:
>>> import google.cloud.logging
>>> client = google.cloud.logging.Client()
I also have my key file located at:
os.path.join(SITE_ROOT, 'utils', 'gcs_testing.json')
Is there a way to manually pass this in python instead of having to export the variable, GOOGLE_APPLICATION_CREDENTIALS
. If so, how would this be done?
Upvotes: 3
Views: 250
Reputation: 110093
This should be pretty simple, you can try the following:
>>> import google.cloud.logging
>>> myFile = os.path.join(SITE_ROOT, 'utils', 'gcs_testing.json')
>>> client=google.cloud.logging.Client.from_service_account_json(myFile)
Now you should be able to write to your logs:
>>> logger=client.logger('log_name')
>>> logger.log_text('hello!')
Upvotes: 3