简体   繁体   English

stackdriver 记录客户端库缺少 python 的严重性

[英]stackdriver logging client library missing severity with python

i would like to send more expressive log entries to stackdriver logging from my app engine standard python3 app.我想从我的应用引擎标准 python3 应用程序向堆栈驱动程序日志发送更具表现力的日志条目。 By following the official documentation i was able to send my logs to stackdriver and it seems that the timestamp is parsed correctly.通过遵循官方文档,我能够将我的日志发送到 stackdriver,并且时间戳似乎被正确解析。

But i'm missing the severity levels.但我错过了严重程度。 In addition i see no way to link logs for a certain request together to a operation.此外,我看不到将某个请求的日志链接到操作的方法。 Something that the java logging seems to be doing out of the box. java日志记录似乎是开箱即用的。

For reference here is my code:供参考,这是我的代码:

import logging
import os

from flask import Flask
from google.cloud import logging as glog

app = Flask(__name__)
log_client = glog.Client(os.getenv('GOOGLE_CLOUD_PROJECT'))
# Attaches a Google Stackdriver logging handler to the root logger
log_client.setup_logging()


@app.route('/_ah/push-handlers/cloudbuild', methods=['POST'])
def pubsub_push_handle():

    logging.info("stdlib info")
    logging.warning("stdlib warn")
    logging.error("stdlib error")

logs resulting in stackdriver:导致堆栈驱动程序的日志:

登录堆栈驱动程序

As you can see the timestamps and message are available while the severity is strangely missing and it gets classified as 'Any'如您所见,时间戳和消息可用,而严重性奇怪地缺失,它被归类为“任何”

Can someone point me in the right direction or is this level of incorporation not yet available?有人可以指出我正确的方向,还是这种级别的合并尚不可用?

Thanks for your time!谢谢你的时间! Carsten卡斯腾

You need to create your own logger and add the google-cloud-logging default handler to it:您需要创建自己的记录器并向其添加google-cloud-logging默认处理程序:

import logging

from flask import Flask
from google.cloud import logging as cloudlogging

log_client = cloudlogging.Client()
log_handler = log_client.get_default_handler()
cloud_logger = logging.getLogger("cloudLogger")
cloud_logger.setLevel(logging.INFO)
cloud_logger.addHandler(log_handler)

app = Flask(__name__)

@app.route('/_ah/push-handlers/cloudbuild', methods=['POST'])
def pubsub_push_handle():
    cloud_logger.info("info")
    cloud_logger.warning("warn")
    cloud_logger.error("error")
    return 'OK'

Produces:产生:

在此处输入图片说明

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

相关问题 google-cloud-logging 模块没有记录到 StackDriver 中正确的严重性过滤器 - The google-cloud-logging module is not logging to the correct severity filters in StackDriver 如何在 python 中设置 stackdriver 日志条目的严重性? - How do I set the severity of a stackdriver log entry in python? python龙卷风日志库 - python tornado logging library 如何将 python 脚本登录到在 Google Cloud VM 上运行的 Google stackdriver 日志记录 - How to logging python script log into Google stackdriver logging running on a Google Cloud VM Stackdriver Logging错过了日志条目 - Stackdriver logging misses log entries 如何重新安装python 3的日志库? - How to reinstall logging library for python 3? 通过模块名称和严重性登录到其他位置 - Logging to different locations via module name and severity stackdriver 日志代理未显示从 Google 云平台上的 stackdriver 日志查看器中的自定义日志文件读取的日志 - stackdriver logging agent not showing logs read from a custom log file in stackdriver logging viewer on Google cloud platform 如何使用 Python 日志库写入 CSV? - How to write to a CSV using Python logging library? 使用Python请求库难以登录帐户 - Difficulty logging in to account with Python requests library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM