【问题标题】:The worker for a Google Cloud Platform task cannot find the logging libraryGoogle Cloud Platform 任务的工作人员找不到日志库
【发布时间】:2018-03-21 18:59:31
【问题描述】:

我创建了一个基于 Google Cloud Platform "update counter" push task example 的简单任务。我要做的就是记录它已被调用到 Stackdriver 日志中。

from google.cloud import logging
logging_client = logging.Client()
log_name = 'service-log'
logger = logging_client.logger(log_name)

import webapp2

class UpdateCounterHandler(webapp2.RequestHandler):
    def post(self):
        amount = int(self.request.get('amount'))
        logger.log_text('Service startup task done.')


app = webapp2.WSGIApplication([
    ('/update_counter', UpdateCounterHandler)
], debug=True)

部署并调用它后,出现错误。在线日志中说:

from google.cloud import logging
ImportError: No module named cloud

这不是本地版本,而是我部署的版本。我很难相信我必须将 python 库实际安装到生产运行时中。 (我什至无法想象我可以。)

【问题讨论】:

    标签: python-2.7 google-cloud-platform google-cloud-stackdriver


    【解决方案1】:

    正如root readme 所说:

    许多示例需要安装额外的库。如果有requirements.txt,则需要安装pip的依赖项。

    尝试按照here 的说明添加库。

    【讨论】:

      【解决方案2】:

      在 App Engine 中使用 Python 标准库中的 logging 时,日志也会最终出现在 Stackdriver 中。所以你可以使用import logging 而不是from google.cloud import logging

      当您对使用 google.cloud.logging 库特别感兴趣时,需要将其安装到 Tudormi 引用的项目文件夹 ./libhere

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-15
        • 2023-03-12
        • 2012-04-24
        • 1970-01-01
        • 2020-02-26
        • 2019-02-21
        • 2019-12-29
        相关资源
        最近更新 更多