如何在 Google App Engine 中写入控制台? [英] How do I write to the console in Google App Engine?

查看:23
本文介绍了如何在 Google App Engine 中写入控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在我编码时,我只是喜欢将一些小东西(主要是变量的当前值)打印到控制台.虽然我注意到 Google App Engine Launcher 确实有一个 Log 终端,但我没有看到 Google App Engine 有这样的东西.有什么方法可以使用 Google App Engine 写入所述终端或其他终端?

解决方案

您需要使用 Python 的标准 logging 模块.

导入日志logging.info("你好")logging.debug("hi") # 默认情况下不会显示

要在 GoogleAppEngineLauncher Logs 控制台中查看对 logging.debug() 的调用,您必须首先向您的应用添加标志 --dev_appserver_log_level=debug.但是,请注意您会看到来自 App Engine SDK 本身的大量调试噪音.

Often when I am coding I just like to print little things (mostly the current value of variables) out to console. I don't see anything like this for Google App Engine, although I note that the Google App Engine Launcher does have a Log terminal. Is there any way to write to said Terminal, or to some other terminal, using Google App Engine?

解决方案

You'll want to use the Python's standard logging module.

import logging

logging.info("hello")
logging.debug("hi") # this won't show up by default

To see calls to logging.debug() in the GoogleAppEngineLauncher Logs console, you have to first add the flag --dev_appserver_log_level=debug to your app. However, beware that you're going to see a lot of debug noise from the App Engine SDK itself. The full set of levels are:

  • debug
  • info
  • warning
  • error
  • critical

You can add the flag by double clicking the app and then dropping it into the Extra Flags field.

这篇关于如何在 Google App Engine 中写入控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆