简体   繁体   English

Python 记录到 GCP StackDriver 缺少日志类型图标

[英]Python logging to GCP StackDriver missing log-type icon

I'm using this approach for sending logs from my GCP App-Engine logic to GCP Stackdriver logging:我正在使用这种方法将日志从我的 GCP App-Engine 逻辑发送到 GCP Stackdriver 日志记录:

import logging
import google.cloud.logging
from google.cloud.logging.handlers import CloudLoggingHandler, setup_logging

client = google.cloud.logging.Client()
handler = CloudLoggingHandler(client)
logging.getLogger().setLevel(logging.INFO) 
setup_logging(handler)

logging.info('just info')
logging.warning('warning info')
logging.error('bad news')

This works and produces logs that are all classified generically and look like this:这有效并产生了所有一般分类的日志,如下所示:

无图标日志条目

However what I'd like to see is the same log but with the associated severity level classification and visually having log-level classification icon, like this in example:但是,我希望看到的是相同的日志,但具有相关的严重性级别分类,并且在视觉上具有日志级别分类图标,如下例所示:

good-icon 日志条目

I've been going through the documentation found here and tried a number of things but all with the same no-icon result.我一直在浏览 此处找到的文档并尝试了很多方法,但结果都相同。 Any advice or recommendations welcome.欢迎任何意见或建议。

What you will have to do is set log severity for each of these entries.您需要做的是为每个条目设置日志严重性。 So for 'just info' for example, you would set the severity to 'info' which will give you that little blue square that shows in you example.例如,对于“只是信息”,您可以将严重性设置为“信息”,这将为您提供示例中显示的那个蓝色小方块。 Check out this link to see all the levels of severity and what they mean.查看此链接以查看所有严重级别及其含义。

After researching the issue and following a number of dead-end leads I happened across this site which provided me a working answer:在研究了这个问题并遵循了一些死胡同后,我偶然发现了这个网站,这为我提供了一个可行的答案:

https://blog.frank-mich.com/python-logging-to-stackdriver/ https://blog.frank-mich.com/python-logging-to-stackdriver/

In short I followed his solution using the Stackdriver formatting via the StreamHandler.简而言之,我通过 StreamHandler 使用 Stackdriver 格式遵循了他的解决方案。 This now allows me to produce proper SEVERITY level formatted log entries that can be properly filtered in GCP Logging:现在,这允许我生成正确的 SEVERITY 级别格式的日志条目,可以在 GCP 日志记录中正确过滤:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM