Skip to content

Commit 5055919

Browse files
feat: use structured logging on GCF with python 3.7 (#434)
1 parent 9d38995 commit 5055919

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

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)

0 commit comments

Comments
 (0)