簡體   English   中英

Google Cloud Stackdriver 忽略 Python 日志中的格式

[英]Google Cloud Stackdriver ignores formatting in Python logs

我正在使用python37運行時部署 Cloud Function。 感謝這個問題,我知道我可以將 Python 本機記錄器連接到 Stackdriver 記錄。 所以我的雲 Function 看起來像這樣:

import logging

logging.basicConfig(format="%(module)s.%(funcName)s: %(message)s", level=logging.INFO)

from google.cloud import logging as glogging
glogging.Client().setup_logging()


def endpoint():
  logging.info("this should be prefixed with main.endpoint")
  return "ok"

但是當我在 Stackdriver 中查看生成的日志時:

  1. 他們忽略了我的格式,這在本地不會發生。
  2. 每個日志出現兩次:一次以其定義的嚴重性,第二次以ERROR嚴重性。

google-cloud-logging中的某些內容似乎只處理消息而忽略了其他所有內容。 有沒有辦法將它傳遞給我定義的格式化程序?

為什么日志會重復?

當我在本地運行代碼時,我得到了這個:

main.endpoint: this should be prefixed with main.endpoint
this should be prefixed with main.endpoint
Waiting up to 5 seconds.
Sent all pending logs.

所以,圖書館似乎在復制日志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM