1

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.

Community
  • 1
  • 1
craftApprentice
  • 2,697
  • 17
  • 58
  • 86

2 Answers2

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.

Wulfram
  • 3,292
  • 2
  • 15
  • 11
  • This explains the I/O error. I use the GAE logging console, but I thought that with this method I could get more detailed logging messages. Thanks! – craftApprentice Aug 14 '12 at 01:40
  • NP, glad I could be of service. – Wulfram Aug 14 '12 at 01:44
  • 1
    @Wulfram there is no log messages in the localhost admin (at least not in mine). the logs are visible in the terminal window. – aschmid00 Aug 14 '12 at 13:30
  • Are you running your app on your machine? My answer was tailored for the author, since the I/O error gave me the clue that he was talking about the cloud environment. On the localmachine, you can see the logs in the terminal or the log console. – Wulfram Aug 15 '12 at 07:36
1

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.')
Sebastian Kreft
  • 7,819
  • 3
  • 24
  • 41