如何在谷歌应用程序引擎中写入控制台?

时间:2020-11-27 02:16:32

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?

通常,当我在编写代码时,我只是喜欢打印一些小的东西(主要是变量的当前值)到控制台。我在谷歌应用程序引擎上看不到这样的东西,尽管我注意到谷歌应用程序引擎启动器确实有一个日志终端。有没有办法用谷歌应用程序引擎写到上述终端或其他终端?

10 个解决方案

#1


65  

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

您将希望使用Python的标准日志记录模块。

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:

要在GoogleAppEngineLauncher日志控制台中看到对logger .debug()的调用,您必须首先将标记——dev_appserver_log_level=debug添加到应用程序中。完整的一套水平是:

  • debug
  • 调试
  • info
  • 信息
  • warning
  • 警告
  • error
  • 错误
  • critical
  • 至关重要的

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

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

如何在谷歌应用程序引擎中写入控制台?

#2


31  

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

看到https://cloud.google.com/appengine/docs/python/requests Python_Logging和http://docs.python.org/library/logging.html

You probably want to use something like:

您可能想要使用以下内容:

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

#3


9  

@Manjoor

@Manjoor

You can do the same thing in java.

在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

在http://code.google.com/appengine/docs/java/runtime.html看到“日志记录”

#4


4  

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:

如果您正在使用Python开发服务器的最新版本(发布> 1.7.6或2013年3月及以后的版本),那么这些似乎是正确的步骤:

  1. Include the following in your script,

    在你的脚本中包含以下内容,

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

    导入日志记录。debug(“我想要记录的内容”)

  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

    ——log_level =调试

#5


2  

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

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

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

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

#6


1  

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.

查看我的在线Python解释器,在我的网站上运行谷歌应用程序引擎,学习Python。这可能就是你要找的。只需在要查看的内容上使用print repr(变量),并执行任意次数。

#7


1  

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:

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

--dev_appserver_log_level debug

——dev_appserver_log_level调试

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

使用它代替调试(参见@Christopher answer)。

#8


0  

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

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

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

#9


0  

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

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

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.

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

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

文本输出到系统。我们也没有出现。它似乎被解释为log.info()级别的消息。

#10


0  

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

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

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

您可以通过单击AppEngine启动器的logs按钮来启动它

#1


65  

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

您将希望使用Python的标准日志记录模块。

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:

要在GoogleAppEngineLauncher日志控制台中看到对logger .debug()的调用,您必须首先将标记——dev_appserver_log_level=debug添加到应用程序中。完整的一套水平是:

  • debug
  • 调试
  • info
  • 信息
  • warning
  • 警告
  • error
  • 错误
  • critical
  • 至关重要的

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

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

如何在谷歌应用程序引擎中写入控制台?

#2


31  

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

看到https://cloud.google.com/appengine/docs/python/requests Python_Logging和http://docs.python.org/library/logging.html

You probably want to use something like:

您可能想要使用以下内容:

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

#3


9  

@Manjoor

@Manjoor

You can do the same thing in java.

在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

在http://code.google.com/appengine/docs/java/runtime.html看到“日志记录”

#4


4  

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:

如果您正在使用Python开发服务器的最新版本(发布> 1.7.6或2013年3月及以后的版本),那么这些似乎是正确的步骤:

  1. Include the following in your script,

    在你的脚本中包含以下内容,

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

    导入日志记录。debug(“我想要记录的内容”)

  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

    ——log_level =调试

#5


2  

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

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

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

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

#6


1  

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.

查看我的在线Python解释器,在我的网站上运行谷歌应用程序引擎,学习Python。这可能就是你要找的。只需在要查看的内容上使用print repr(变量),并执行任意次数。

#7


1  

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:

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

--dev_appserver_log_level debug

——dev_appserver_log_level调试

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

使用它代替调试(参见@Christopher answer)。

#8


0  

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

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

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

#9


0  

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

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

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.

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

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

文本输出到系统。我们也没有出现。它似乎被解释为log.info()级别的消息。

#10


0  

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

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

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

您可以通过单击AppEngine启动器的logs按钮来启动它