我每分钟都在运行一个云功能。
空行(请参阅下面的日志)间歇性地出现在 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"
最佳答案
同时,您可以向 stackdriver 添加过滤器以跳过带有空字符串的日志。
关于python - 为什么 Stackdriver 日志中会间歇性地出现空行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58983677/