简体   繁体   English

使用带Python的Google App Engine无法看到调试打印语句

[英]Can't see debug print statements using Google App Engine with python

I am new to both Google App Engine and Python. 我是Google App Engine和Python的新手。 When things go wrong I'd like to see variable values and such, but print statements don't seem to be output anywhere. 当出现问题时,我希望看到变量值等等,但是print语句似乎没有输出到任何地方。 I would have expected them to appear in the same window where I started dev_appserver, but the only time I can see them is if a server error is imminent, then they appear in the output as I'd expect, right before the server error. 我本来希望它们出现在启动dev_appserver的同一窗口中,但是我唯一能看到的是如果即将发生服务器错误,那么它们就会出现在服务器错误之前的预期输出中。 Otherwise I don't see them. 否则我看不到他们。

I'm sure I'm missing something very fundamental... it seems everyone else can see their print statements just fine. 我确定我缺少了一些非常基本的东西……似乎其他所有人都可以看到他们的印刷声明。 I have tried using the logger functionality, but best I can tell it is intended for deployed apps. 我尝试使用记录器功能,但最好的办法是将其用于已部署的应用程序。 At any rate I can't see any output from those either. 无论如何,我都看不到任何输出。 A simple example: 一个简单的例子:

class PageHandler(BaseHandler):
def get(self): 
    // the page renders just fine, but no print statement to be found
    print "rendering the page!"        
    self.render("page.html")

Am I just looking in the wrong spot for the print output? 我只是在寻找错误的打印输出位置吗? Do I need to be doing something to redirect output before printing? 打印前是否需要做一些重定向输出的操作? Very confused why the print statements work only when an error is about to occur. 非常困惑为什么打印语句仅在即将发生错误时才起作用。

print outputs to standard output ( sys.stdout ) whose destination on a web app is always iffy. 将输出print到标准输出( sys.stdout ),该输出在Web应用程序上的目标始终是iffy。 Rather, use the logging module...: 而是使用logging模块...:

import logging
...
logging.info('rendering the page')

and you'll be able to see all messages in the logs. 并且您将能够查看日志中的所有消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM