【问题标题】:How to see logging module output module under GAE?GAE下如何查看日志模块输出模块?
【发布时间】:2012-08-10 06:24:18
【问题描述】:

我正在尝试调试this code。带着这个目标,我尝试在this tutorial 之后使用日志记录。为了这个目标,我将这段代码插入到我的脚本中:

import logging

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

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

并且,在我想要获取消息记录的部分中,我插入了以下行:logging.debug ('This is a log message.') 这样:

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)

原来我的应用程序是一个 GAE 应用程序。而且我看不到日志消息,它没有出现在浏览器或 PyScripter IDE 中。我应该在哪里看到带有日志记录消息的屏幕?

PS - 我尝试使用此代码将日志消息交替写入文件:

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.') 

但我发现一个 I/O 错误。

【问题讨论】:

    标签: python google-app-engine logging


    【解决方案1】:

    您是在尝试在 Google App Engine 上运行记录器,还是在您的本地计算机上无法运行?如果它在 GAE 上不起作用,那是因为您已将记录器设置为写入文件,而 GAE 并没有真正让您访问文件系统。

    对于非基于文件的日志,您可以在 GAE 管理控制台中找到这些日志。 (在您的本地主机上,它位于

    http://localhost:8080/_ah/admin
    

    请参阅https://developers.google.com/appengine/articles/logging,了解如何使用在 GAE 上运行的日志记录模块。

    【讨论】:

    • 这解释了 I/O 错误。我使用 GAE 日志控制台,但我认为使用这种方法可以获得更详细的日志消息。谢谢!
    • NP,很高兴我能提供服务。
    • @Wulfram localhost 管理员中没有日志消息(至少在我的中没有)。日志在终端窗口中可见。
    • 您是否在您的机器上运行您的应用程序?我的回答是为作者量身定做的,因为 I/O 错误让我知道他在谈论云环境。在本地机器上,您可以在终端或日志控制台中看到日志。
    【解决方案2】:

    我无法为您提供有关 PyScripter 的详细信息,但您需要设置 IDE 以将 -d(或 --debug)标志传递给 dev_appserver.py。这将启用DEBUG 日志,否则您将只能看到INFO 或更高级别的消息。

    所以你可以试试:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 2013-12-10
      • 1970-01-01
      • 2013-10-17
      • 2015-04-05
      • 2023-04-06
      • 2020-11-03
      相关资源
      最近更新 更多