50

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?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Stephen Cagle
  • 14,124
  • 16
  • 55
  • 86

11 Answers11

68

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

Chris Calo
  • 7,518
  • 7
  • 48
  • 64
32

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))
Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
vartec
  • 131,205
  • 36
  • 218
  • 244
  • 1
    How can i do the same in java? – Manjoor Jun 26 '10 at 12:33
  • 14
    You'll most likely want to use logging.info() instead of logging.debug() because the default logging level in the GoogleAppEngineLauncher Logs console is such that you won't see any calls to logging.debug(). – Chris Calo Mar 12 '12 at 00:26
  • The first link to the Logging for Python GAE is broken. It should be updated to https://cloud.google.com/appengine/docs/python/requests#Python_Logging – Jesse Webb Dec 17 '14 at 17:21
9

@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

Dario Seidl
  • 4,140
  • 1
  • 39
  • 55
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:

  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

user809695
  • 179
  • 8
2

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/

Sam
  • 6,240
  • 4
  • 42
  • 53
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:

--dev_appserver_log_level debug

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

Abimael
  • 11
  • 2
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.

Ron Reiter
  • 3,852
  • 3
  • 30
  • 34
0

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

print >> sys.stderr, "Something to log."
bugloaf
  • 2,890
  • 3
  • 30
  • 49
0

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.

Ribo
  • 3,363
  • 1
  • 29
  • 35
0

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

0

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.

clickbait
  • 2,818
  • 1
  • 25
  • 61