python - 为什么 Stackdriver 日志中会间歇性地出现空行?

标签 python python-3.x google-cloud-functions google-cloud-logging

我每分钟都在运行一个云功能。

空行(请参阅下面的日志)间歇性地出现在 Stackdriver 日志中。

我不相信这是由于我编写的函数代码。

可以使用这个 main.py 重新创建错误:

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info(f"Logging {__name__}")


def main(event, context):
    logger.info("Message 1")
    logger.info("Message 2")
    logger.info("Message 3")

当 Cloud Scheduler 每分钟触发一次时,此函数会在几个小时内发出空行。

如何防止这个问题?

更新:添加了两个扩展日志
{
 insertId: "000001-redacted-but-identical"  
 labels: {
  execution_id: "894004659398898"   
 }
 logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp: "2019-12-13T23:05:01.545007423Z"  
 resource: {
  labels: {
   function_name: "recreate_blank_lines"    
   project_id: "redacted"    
   region: "us-central1"    
  }
  type: "cloud_function"   
 }
 severity: "INFO"  
 timestamp: "2019-12-13T23:05:00.344Z"  
 trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0"  
}

{
 insertId: "000000-redacted-but-identical"  
 labels: {
  execution_id: "894004659398898"   
 }
 logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp: "2019-12-13T23:05:01.545007423Z"  
 resource: {
  labels: {
   function_name: "recreate_blank_lines"    
   project_id: "redacted"    
   region: "us-central1"    
  }
  type: "cloud_function"   
 }
 severity: "INFO"  
 textPayload: "Message 2"  
 timestamp: "2019-12-13T23:05:00.345Z"  
 trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0" 

Blank log example

Blank log example 2

最佳答案

同时,您可以向 stackdriver 添加过滤器以跳过带有空字符串的日志。

关于python - 为什么 Stackdriver 日志中会间歇性地出现空行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58983677/

相关文章:

python - mininet-wifi/examples/handover.py 抛出错误

python-3.x - Pandas read_parquet() 错误 : pyarrow. lib.ArrowInvalid:从时间戳 [us] 转换到时间戳 [ns] 将导致时间戳超出范围

imagemagick - 我可以访问 Google Cloud Function 中的 GraphicsMagicks 或 ImageMagicks 吗?

node.js - Firebase反向dns查找ENOTFOUND错误node.js dns

google-cloud-platform - Google 无服务器 VPC 连接器无法访问具有多个网络接口(interface)的 GCE 实例

python - 如何以行 block 的形式检查进程的持续时间?

python - 将类别列表打印为一列

Python Byte 不打印二进制文件

python - 调试 Python ANTLR4 语法

python - 如何在 python 中将 Avro 文件转换为 CSV 文件?