How to see logging module output module under GAE?

余生颓废 提交于 2020-01-05 04:34:41

问题


I'm trying to debug this code. With this goal, I'm trying to use logging following this tutorial. With this goal, I insert this code in my script:

import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

logging.debug('This is a log message.')

And, in the section where I wanted to get the message logging, I inserted the line: logging.debug ('This is a log message.') this way:

def fcount(self,f,cat):
    res = db.GqlQuery("SELECT * FROM fc WHERE feature =:feature AND category =:category", feature = f, category = cat).get()
    logging.debug('This is a log message.')
#    res=self.con.execute(
#      'select count from fc where feature="%s" and category="%s"'
#      %(f,cat)).fetchone()
    if res is None: return 0
    else:
        res = fc.count
        return float(res)

It turns out that my application is an GAE application. And I cannot see the logging message, which doesn't appear in the browser or in PyScripter IDE. Where should I see the screen with the logging message?

PS - I tried use this code to alternately write logging messages to a file:

import logging
logging.basicConfig(filename='log_filename.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
logging.debug('This is a log message.') 

But I find one I/O error.


回答1:


Are you trying to run the logger on the Google App Engine or is it not working on your local machine? If it's not working on GAE, it's because you have setup the logger to write to a file, and GAE does not really let you access the file system.

For the non-file-based log, you would find the logs in the GAE admin console. (On your localhost, it is located at

http://localhost:8080/_ah/admin

See https://developers.google.com/appengine/articles/logging on how to use the logging module running on GAE.




回答2:


I cannot give you specifics about PyScripter, but you need to set your IDE to pass the -d (or --debug) flag to the dev_appserver.py. That enables DEBUG logs, otherwise you will see only messages of level INFO or higher.

So you could try instead:

logging.info('This is a log message.')


来源:https://stackoverflow.com/questions/11944206/how-to-see-logging-module-output-module-under-gae

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!