Skip to content

Commit d7e5870

Browse files
feat: use structured logging on GCF with python 3.7 (#434)
1 parent bbdaaac commit d7e5870

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

packages/google-cloud-logging/google/cloud/logging_v2/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,9 @@ def get_default_handler(self, **kw):
355355
return AppEngineHandler(self, **kw)
356356
elif monitored_resource.type == _GKE_RESOURCE_TYPE:
357357
return ContainerEngineHandler(**kw)
358-
elif (
359-
monitored_resource.type == _GCF_RESOURCE_TYPE
360-
and sys.version_info[0] == 3
361-
and sys.version_info[1] >= 8
362-
):
363-
# Cloud Functions with runtimes > 3.8 supports structured logs on standard out
364-
# 3.7 should use the standard CloudLoggingHandler, which sends logs over the network.
358+
elif monitored_resource.type == _GCF_RESOURCE_TYPE:
359+
# __stdout__ stream required to support structured logging on Python 3.7
360+
kw["stream"] = kw.get("stream", sys.__stdout__)
365361
return StructuredLogHandler(**kw, project_id=self.project)
366362
elif monitored_resource.type == _RUN_RESOURCE_TYPE:
367363
return StructuredLogHandler(**kw, project_id=self.project)

tests/environment

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 17b7a46908320891605908d5baa5f32eb255380e
1+
Subproject commit dc85066053b8dc2246c8b72f93a5b97f92885eb2

0 commit comments

Comments
 (0)