logservice.fetch()没有返回任何内容

时间:2012-03-20 14:17:12

标签: python api google-app-engine logging

以下代码用于从应用引擎获取日志以进行进一步处理。但是我不知道如何使用logservice.fetch的结果来访问日志消息?

import cgi
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api.logservice import logservice
logservice.AUTOFLUSH_ENABLED = False

class MainPage(webapp.RequestHandler):
    def get(self):  
        requestlogs = logservice.fetch(start_time=1332200000, end_time=1332249954, offset=None, minimum_log_level=logservice.LOG_LEVEL_INFO, include_incomplete=False, include_app_logs=True, version_ids=None, batch_size=None)
        self.response.out.write(requestlogs)
        c=0
        for iter in requestlogs:
           c=c+1  
        print c
application = webapp.WSGIApplication([('/logs', MainPage)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

1 个答案:

答案 0 :(得分:3)

在您的情况下,代码看起来像这样:

from google.appengine.api import logservice

MAX_LOGS_TO_READ = 10

class MainPage(webapp.RequestHandler):

  def get(self):  
    request_logs = logservice.fetch()
    current_log = 0
    for log in request_logs:
      if current_log > MAX_LOGS_TO_READ:
        break
    self.response.out.write(log.combined)

几条评论..