向 CloudLoggingHandler class 提供 "resource" 参数无效
Providing "resource" argument to CloudLoggingHandler class does't work
向CloudLoggingHandler
class 提供resource
参数无效,即无法登录到stackdriver
。如果我将 resource
注释掉,它就可以正常工作。我还尝试了一个简单的 python 脚本,它在 Django 中没有 运行,它也工作得很好。
这实际上是我的 Django LOGGING 处理程序设置:
'handlers': {
'stderr': {
'class': 'google.cloud.logging.handlers.CloudLoggingHandler',
'name': "name",
'resource': Resource(
type="container",
labels={
...
},
),
'client': google.cloud.logging.Client()
},
},
没有resource
,没有问题:
'handlers': {
'stderr': {
'class': 'google.cloud.logging.handlers.CloudLoggingHandler',
'name': "name",
'client': google.cloud.logging.Client()
},
},
一个简单的脚本也可以:
import logging
import google.cloud.logging # Don't conflict with standard logging
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging
from google.cloud.logging.resource import Resource
client = google.cloud.logging.Client()
logging.getLogger().setLevel(logging.INFO) # defaults to WARN
res = Resource(
type="container",
labels={
...
},
)
handler = CloudLoggingHandler(client, name='name', resource=res)
setup_logging(handler)
logging.error('logging!')
我用的google-cloud-logging
版本是1.10.0
。
有人可以提供一些关于调试 stackdriver
日志记录的建议吗?
此问题很可能是由于资源格式不正确引起的,原因可能是类型不受支持(或不再受支持)、标签与给定类型的预期标签不匹配、缺少必需的标签、或者因为需要特殊权限才能针对有问题的特定资源类型写入日志。
在这种特殊情况下,使用 container
而不是 k8s_container
看起来很可疑。基于 this conversation as well as the existence of k8s_container
in the list of Stackdriver Monitoring resource types as well as Stackdriver Logging resource types,而 container
仅记录在后者上,这可能是已被 k8s_container
.
取代的弃用资源类型
如果这不起作用,则写入远程日志失败应该在本地生成日志(或使用附加到 background thread transport 的任何处理程序);尽管这些日志显然更难访问,但如果您可以访问这些日志,应该可以看到尝试写入 Stackdriver Logging 时出了什么问题。
向CloudLoggingHandler
class 提供resource
参数无效,即无法登录到stackdriver
。如果我将 resource
注释掉,它就可以正常工作。我还尝试了一个简单的 python 脚本,它在 Django 中没有 运行,它也工作得很好。
这实际上是我的 Django LOGGING 处理程序设置:
'handlers': {
'stderr': {
'class': 'google.cloud.logging.handlers.CloudLoggingHandler',
'name': "name",
'resource': Resource(
type="container",
labels={
...
},
),
'client': google.cloud.logging.Client()
},
},
没有resource
,没有问题:
'handlers': {
'stderr': {
'class': 'google.cloud.logging.handlers.CloudLoggingHandler',
'name': "name",
'client': google.cloud.logging.Client()
},
},
一个简单的脚本也可以:
import logging
import google.cloud.logging # Don't conflict with standard logging
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging
from google.cloud.logging.resource import Resource
client = google.cloud.logging.Client()
logging.getLogger().setLevel(logging.INFO) # defaults to WARN
res = Resource(
type="container",
labels={
...
},
)
handler = CloudLoggingHandler(client, name='name', resource=res)
setup_logging(handler)
logging.error('logging!')
我用的google-cloud-logging
版本是1.10.0
。
有人可以提供一些关于调试 stackdriver
日志记录的建议吗?
此问题很可能是由于资源格式不正确引起的,原因可能是类型不受支持(或不再受支持)、标签与给定类型的预期标签不匹配、缺少必需的标签、或者因为需要特殊权限才能针对有问题的特定资源类型写入日志。
在这种特殊情况下,使用 container
而不是 k8s_container
看起来很可疑。基于 this conversation as well as the existence of k8s_container
in the list of Stackdriver Monitoring resource types as well as Stackdriver Logging resource types,而 container
仅记录在后者上,这可能是已被 k8s_container
.
如果这不起作用,则写入远程日志失败应该在本地生成日志(或使用附加到 background thread transport 的任何处理程序);尽管这些日志显然更难访问,但如果您可以访问这些日志,应该可以看到尝试写入 Stackdriver Logging 时出了什么问题。