开发者

How do execute print command in google app engine?

Am doing development on google app engine and i want to print out values that are sent to the server from the browser. When i insert the print commands in my handlers nothing get printed on the console running the local server!

How do i get around this?

开发者_开发技巧

Gath


Rather than just printing out values, use the logging module. This is generally good practice anyway as it means you can potentially leave in some handy debug output even when you are running in production mode.

import logging
logging.error("This is an error message that will show in the console")

By default dev_appserver.py will not show any messages below logging-level INFO, but you can run dev_appserver.py with the --debug flag and then you will be able to see output from the lower logging.DEBUG level and scatter various logging calls in your code like:

logging.debug("some helpful debug info")

If you leave these in once your app is in production, then these will be visible in your app's admin area in the logs section.


As @Chris Farmiloe suggested you should use the logging module . Google appengine by default supports logging modlue. You can see various levels of logs for your applications in appengine console. Logging module comes in handy in the production enviroment. Where you can see all your logs. For general info use

logging.info('This is just for information')


self.response.out.write("Hallo World")


Using Go Language (I don't know if this works with the other languages), you can do that through the appengine.Context.Debugf function https://developers.google.com/appengine/docs/go/reference#Context

func yourfunction (r *http.Request){
    c := appengine.NewContext(r)
    c.Debugf("%v\n","Your message")
    ....
}

You may have to set the minimum log_level in the development server:

dev_appserver.py --log_level debug [your application]


When I want a quick and dirty way to print out some info, I do this:

assert False, "Helpful information"

after getting the needed info, I delete the line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜