[英]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.