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.)
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 withpip
.
Try adding the library as explained here .
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.