![](/img/trans.png)
[英]Can I Increase the Number of Log Entries in Google App Engine? (python)
[英]Duplicated log entries in Google App Engine (Python 3)
我正在努力找出為什么我的日志條目在 Cloud Logging 中重復。 我使用了一個什么都不做的自定義虛擬處理程序,而且我還使用了一個命名記錄器。
這是我的代碼:
import google.cloud.logging
import logging
class MyLogHandler(logging.StreamHandler):
def emit(self, record):
pass
# Setting Up App Engine's Logging
client = google.cloud.logging.Client()
client.get_default_handler()
client.setup_logging()
# Setting Up my custom logger/handler
my_handler = MyLogHandler()
logging.getLogger('my_logger').addHandler(my_handler)
logging.getLogger('my_logger').setLevel(logging.DEBUG)
logging.getLogger('my_logger').debug('Why this message is being duplicated?') # please note that i'm logging into 'my_logger' logger, I'm not using root logger for this message
首先,我認為這條消息甚至不應該顯示在 Cloud Logging 中,因為我使用的是名為“my_logger”的命名記錄器,並且雲日志記錄僅附加到根記錄器,但無論如何......
上面的代碼被導入到我的 app.py 中,它在 App Engine 上引導了一個 Flask 應用程序。
這是問題的屏幕截圖:
這個人有一個類似的問題: Duplicate log entries with Google Cloud Stackdriver logging of Python code on Kube.netes Engine
但是我嘗試了該主題中建議的所有解決方法,但都沒有用。 我在這里缺少什么嗎? 提前致謝。
from google.cloud.logging.handlers import AppEngineHandler
root_logger = logging.getLogger()
# use the GCP appengine handlers only in order to prevent logs from getting written to STDERR
root_logger.handlers = [handler for handler in root_logger.handlers
if isinstance(handler, AppEngineHandler)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.