How to see logging module output module under GAE?

2019-07-26 01:37发布

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.

2条回答
相关推荐>>
2楼-- · 2019-07-26 01:50

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.')
查看更多
男人必须洒脱
3楼-- · 2019-07-26 01:55

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.

查看更多
登录 后发表回答