0
votes

I am using Python on Google app engine. I am logging both errors and info level messages. As per documentation, I should see messages in Google App engine logs, however there are no messages visible. My code below and Log output is below. Please point out, why I am not seeing messages in Google app engine logs. The code is a sample Photohunt service and I am trying to modify it.

My code:

def post(self):
"""Exposed as `POST /api/photos`.

Takes the following payload in the request body.  Payload represents a
Photo that should be created.
{
  'id':0,
  'ownerUserId':0,
  'ownerDisplayName':'',
  'ownerProfileUrl':'',
  'ownerProfilePhoto':'',
  'themeId':0,
  'themeDisplayName':'',
  'numVotes':0,
  'voted':false, // Whether or not the current user has voted on this.
  'created':0,
  'fullsizeUrl':'',
  'thumbnailUrl':'',
  'voteCtaUrl':'', // URL for Vote interactive post button.
  'photoContentUrl':'' // URL for Google crawler to hit to get info.
}

Returns the following JSON response representing the created Photo.
{
  'id':0,
  'ownerUserId':0,
  'ownerDisplayName':'',
  'ownerProfileUrl':'',
  'ownerProfilePhoto':'',
  'themeId':0,
  'themeDisplayName':'',
  'numVotes':0,
  'voted':false, // Whether or not the current user has voted on this.
  'created':0,
  'fullsizeUrl':'',
  'thumbnailUrl':'',
  'voteCtaUrl':'', // URL for Vote interactive post button.
  'photoContentUrl':'' // URL for Google crawler to hit to get info.
}


Issues the following errors along with corresponding HTTP response codes:
400: 'Bad Request' if the request is missing image data.
401: 'Unauthorized request' (if certain parameters are present in the
     request)
401: 'Access token expired' (there is a logged in user, but he doesn't
     have a refresh token and his access token is expiring in less than
     100 seconds, get a new token and retry)
500: 'Error while writing app activity: ' + error from client library.
"""
try:
 user = self.get_user_from_session()
 current_theme = model.Theme.get_current_theme()
 //mthemeId = self.request.get('themeId')   
 console.log("Check not working or working. Please work")   
 logger.debug("Writing photo x" )
 mthemeId = self.request.get('themeId')
 logging.info("Error while writing app activity: %s", mthemeId)

 logger = logging.getLogger(__name__)
 logger.setLevel(logging.DEBUG)

 logging.debug("Debug info "+mthemeId)
current_theme = self.request.get('themeId')
current_theme = model.Theme.all().filter('theme_id =', long(mthemeId))
  if current_theme:
    uploads = self.get_uploads('image')
    blob_info = uploads[0]
    photo = model.Photo(owner_user_id=user.key().id(),
        owner_display_name=user.google_display_name,
        owner_profile_photo=user.google_public_profile_photo_url,
        owner_profile_url=user.google_public_profile_url,
        theme_id=current_theme.key().id(),
        theme_display_name=current_theme.display_name,
        created=datetime.datetime.now(),
        num_votes=0,
        image_blob_key=blob_info.key())
    photo.put()
    try:
      result = self.add_photo_to_google_plus_activity(user, photo,mthemeId)
    except apiclient.errors.HttpError as e:
      logging.error("Error while writing app activity: %s", str(e))
    self.send_success(photo)
  else:
logging.error("Error while writing app activity: %s", mthemeId)
    self.send_error(404, "Current theme not there")
except UserNotAuthorizedException as e:
  self.send_error(401, e.msg)

Log 2014-06-06 20:17:04.620 /api/photos 404 21ms 0kb PhotoHunt Agent module=default version=1 0.1.0.30 - - [06/Jun/2014:07:47:04 -0700] "POST /api/photos HTTP/1.1" 404 102 - "PhotoHunt Agent" "my-moments.appspot.com" ms=21 cpu_ms=0 cpm_usd=0.000011 app_engine_release=1.9.5 instance=00c61b117cfb67f2ae092dbf7270939f50631e97 I 2014-06-06 20:17:04.610 make: Got type I 2014-06-06 20:17:04.611 validate: Got type

There are no messages from the Post which were scripted using Logging.debug or Logging.error? How can I see these messages. The documentation says that they should be available in Logs but I do not see any. Any help/pointers are really appreciated.

1

1 Answers

1
votes

What is being logged is a 404 for /api/photos, so your url mapping for that url is not correct or missing.

Also, you will be getting 500 errors with this code. console.log("Check not working or working. Please work") is javascript syntax, not Python. logger.debug("Writing photo x" ) will throw an exception, because you haven't declared logger yet. That should be logging.debug.

And, make sure you have import logging