My favorites | English | Sign in

Google App Engine

LogService API Reference

The google.appengine.api.logservice package provides methods allowing applications to periodically flush logs during long-running requests.

This package has the following functions:

flush()

Flushes log lines that are currently buffered.

flush_time()

Returns the last time that the log buffer was flushed.

log_buffer_contents()

Returns the contents of the logs buffer.

log_buffer_bytes()

Returns the size of the log buffer, in bytes.

log_buffer_lines()

Returns the number of log lines currently buffered.

auto_flush()

This method is invoked automatically to flush logs in the background. You can tune the autoflush function with the following constants:

  • logservice.AUTOFLUSH_ENABLED – Controls whether the in-process logs buffer is automatically flushed during a request. If false, logs are flushed at the end of each request. If true, automatically flushes the log buffer in the background.
  • logservice.AUTOFLUSH_EVERY_SECONDS – If auto_flush() is enabled, flushes the logs buffer after this many seconds.
  • logservice.AUTOFLUSH_EVERY_BYTES – If auto_flush() is enabled, flushes the logs buffer once this many bytes have been logged.
  • logservice.AUTOFLUSH_EVERY_LINES – If auto_flush() is enabled, flushes the logs buffer once this many lines have been logged.

These are module-level variables that apps can change directly. For example, you can disable autoflush entirely as follows:

from google.appengine.api import logservice
logservice.AUTOFLUSH_ENABLED = False

# When you want to flush manually, do this
logservice.flush()

To flush every 20 lines, with no limit on time or bytes:

from google.appengine.api import logservice
logservice.AUTOFLUSH_EVERY_SECONDS = None
logservice.AUTOFLUSH_EVERY_BYTES = None
logservice.AUTOFLUSH_EVERY_LINES = 20 # The default, but set here for clarity

Google recommends that you flush logs regularly. The RPCs are very fast, and not flushing your logs can make debugging difficult.