Python Google Cloud Function Logging Severity and Duplicates(Python Google Cloud Function 记录严重性和重复项)
问题描述
我正在开发一个在 Python 运行时中运行的简单 Google Cloud Function,我想要一些从 Python 程序到 Stackdriver Logging 的简单日志记录.
根据 Google 的启动指南,这应该是直截了当的1.信息被重复为错误2. 调试不通过3. 警告重复,但都是错误日志级别4.错误重复
我在配置中缺少什么吗?
您需要创建自己的 logger 并为其添加 google-cloud-logging
默认处理程序:
导入日志从烧瓶进口烧瓶从 google.cloud 导入日志记录为 cloudlogginglog_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)def logging_test_background(数据,上下文):cloud_logger.info("信息")cloud_logger.warning(警告")cloud_logger.error("错误")返回确定"
生产:
I'm working on a simple Google Cloud Function that runs in the Python runtime and I want some simple logging from the Python program to Stackdriver Logging.
Based on Google's startup guide, this should be straighforward https://cloud.google.com/logging/docs/setup/python
I set up a simple test function to isolate the logging issues I'm seeing
import google.cloud.logging
def logging_test_background(data, context):
logging_client = google.cloud.logging.Client()
logging_client.setup_logging()
logging.info("This should be info")
logging.debug("This should be debug")
logging.warning("This should be warning")
logging.error("This should be error")
In Stackdriver Logging everything gets jumbled. 1. Info is duplicated as an Error 2. Debug doesn't come through 3. Warning is duplicated, but both are error logging level 4. Error is duplicated
Is there something I'm missing in the configuration?
You need to create your own logger and add the google-cloud-logging
default handler to it:
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)
def logging_test_background(data, context):
cloud_logger.info("info")
cloud_logger.warning("warn")
cloud_logger.error("error")
return 'OK'
Produces:
这篇关于Python Google Cloud Function 记录严重性和重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python Google Cloud Function 记录严重性和重复项


基础教程推荐
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 求两个直方图的卷积 2022-01-01