Doug Knesek
Doug Knesek

Reputation: 6727

The worker for a Google Cloud Platform task cannot find the logging library

I have created a simple task based on the Google Cloud Platform "update counter" push task example. All I want to do is log that it has been invoked to the Stackdriver logs.

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)

After deploying this and invoking it, there is an error. In the logs online it says:

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

This isn't a local version, but one that I've deployed. It's hard for me to believe that I have to actually install python libraries into the production runtime. (I can't even imagine that I can.)

Upvotes: 0

Views: 62

Answers (2)

Taavi
Taavi

Reputation: 135

When using logging from the Python standard library in App Engine, the logs also end up in Stackdriver. So you could use import logging instead of from google.cloud import logging.

When you are specifically interested in using the google.cloud.logging library, then it needs to be installed to a project folder ./lib as referred by Tudormi: here

Upvotes: 0

Tudormi
Tudormi

Reputation: 1112

As the root readme states:

Many samples require extra libraries to be installed. If there is a requirements.txt, you will need to install the dependencies with pip.

Try adding the library as explained here.

Upvotes: 1

Related Questions