如何写入 Google App Engine 中的控制台?

发布于 2024-07-16 18:55:19 字数 157 浏览 7 评论 0 原文

通常,当我编码时,我只是喜欢将一些小东西(主要是变量的当前值)打印到控制台。 尽管我注意到 Google App Engine 启动器确实有一个日志终端,但我没有看到 Google App Engine 有类似的情况。 有没有办法使用 Google App Engine 写入所述终端或其他终端?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

饮惑 2024-07-23 18:55:20

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

import logging

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

要在 GoogleAppEngineLauncher 日志控制台中查看对 logging.debug() 的调用,您必须首先将标记 --dev_appserver_log_level=debug 添加到您的应用。 但是,请注意,您会看到 App Engine SDK 本身产生的大量调试噪音。 全套级别是:

  • debug
  • info
  • warning
  • error
  • ritic

您可以通过双击来添加标志应用程序,然后将其放入额外标志字段中。

添加 - GoogleAppEngineLauncher 中您的应用的 -dev_appserver_log_level 标志

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.

Adding the --dev_appserver_log_level flag to your app in the GoogleAppEngineLauncher

最冷一天 2024-07-23 18:55:20

请参阅 https://cloud.google.com/appengine/docs/python/requests# Python_Logging
http://docs.python.org/library/logging.html

你可能想要使用类似的东西:

logging.debug("value of my var is %s", str(var))

See https://cloud.google.com/appengine/docs/python/requests#Python_Logging
and http://docs.python.org/library/logging.html

You probably want to use something like:

logging.debug("value of my var is %s", str(var))
思慕 2024-07-23 18:55:20

@Manjoor

你可以在java中做同样的事情。

import java.util.logging.Logger;
// ...

public class MyServlet extends HttpServlet {
    private static final Logger log = Logger.getLogger(MyServlet.class.getName());

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        log.info("An informational message.");

        log.warning("A warning message.");

        log.severe("An error message.");
    }
}

请参阅 http://code.google.com/appengine/docs/ 中的“日志记录” java/runtime.html

@Manjoor

You can do the same thing in java.

import java.util.logging.Logger;
// ...

public class MyServlet extends HttpServlet {
    private static final Logger log = Logger.getLogger(MyServlet.class.getName());

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        log.info("An informational message.");

        log.warning("A warning message.");

        log.severe("An error message.");
    }
}

See "Logging" in http://code.google.com/appengine/docs/java/runtime.html

撩心不撩汉 2024-07-23 18:55:20

如果您使用的是较新版本的 Python 开发服务器(版本 > 1.7.6,或 2013 年 3 月及更高版本),这些似乎是正确的使用步骤:

  1. 在脚本中包含以下内容,< /p>

    导入日志记录
    logging.debug("something I Want to log")

  2. 并且按照 此文档页面,通过转到“编辑”>“设置标记” 应用程序设置> 启动设置> 额外的命令行标志,并添加,

    --log_level=debug

If you're using a more recent version of the Python Development Server (releases > 1.7.6, or Mar 2013 and later), these seem to be the right steps to use:

  1. Include the following in your script,

    import logging
    logging.debug("something I want to log")

  2. And per this docs page, set a flag by going to Edit > Application Settings > Launch Settings > Extra Command Line Flags, and adding,

    --log_level=debug

愛放△進行李 2024-07-23 18:55:20

您还应该看看 FirePython。 它允许您在 firebug 中获取服务器日志消息。

http://appengine-cookbook.appspot.com/recipe /firepython-logger-console-inside-firebug/

You should also give FirePython a look. It allows you to get server log messages in firebug.

http://appengine-cookbook.appspot.com/recipe/firepython-logger-console-inside-firebug/

冰葑 2024-07-23 18:55:20

在我的网站学习 Python 上查看在 Google App Engine 上运行的在线 Python 解释器。 这可能就是您正在寻找的。 只需对您想要查看的内容使用 print repr(variable) 即可,并执行任意多次。

Check out my online Python interpreter running on Google App Engine on my website, Learn Python. It might be what you're looking for. Just use print repr(variable) on things you want to look at, and execute as many times as you want.

旧城烟雨 2024-07-23 18:55:20

您好,我使用的是 GoogleAppEngineLauncher 1.8.6 版本,您可以使用标志来设置您想要查看的消息日志级别,例如调试消息:

--dev_appserver_log_level debug

使用它而不是--debug (参见@Christopher 的回答)。

Hello I'm using the version 1.8.6 of GoogleAppEngineLauncher, you can use a flag to set the messages log level you want to see, for example for debug messages:

--dev_appserver_log_level debug

Use it instead of --debug (see @Christopher answer).

她说她爱他 2024-07-23 18:55:20

GAE 将捕获标准错误并将其打印到控制台或日志。

print >> sys.stderr, "Something to log."

GAE will capture standard error and print it to the console or to a log.

print >> sys.stderr, "Something to log."
记忆消瘦 2024-07-23 18:55:20

使用 log.setLevel(Level.ALL) 查看消息

默认的消息过滤级别似乎是“错误”。 在使用 setLevel() 方法使 .info 和 .warning 消息可见之前,我没有看到任何有用的日志消息。

打印到 System.out 的文本也没有显示。 它似乎被解释为 log.info() 级别的消息。

Use log.setLevel(Level.ALL) to see messages

The default message filtering level seems to be 'error'. I didn't see any useful log messages until I used the setLevel() method to make the .info and .warning messages visible.

Text printed to System.out wasn't showing up either. It seems to be interpreted as log.info() level messaages.

无人问我粥可暖 2024-07-23 18:55:20

我希望我正在回答这个问题。 日志消息打印到 AppEngine 日志而不是终端。

你可以启动它
点击 AppEngine 启动器的日志按钮

I hope i am answering the question. The logging messages print to the AppEngine log rather than the terminal.

You can launch it
by clicking on the logs button of the AppEngine Launcher

卖梦商人 2024-07-23 18:55:20

使用 logging 模块是很好的做法,< /a> 但这不是必需的。

您只需执行普通的 print() 即可写入 Google App Engine 日志控制台。

Using the logging module is good practice, but it's not required.

You can just do plain-old print()s to write to the Google App Engine Log Console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文