English

Google App Engine

Functions

The google.appengine.api.logservice package provides functions allowing applications to periodically flush logs during long-running requests and to examine an application's request logs and application logs.

This package has the following functions:

fetch(start_time=None, end_time=None, offset=None, minimum_log_level=None, include_incomplete=False, include_app_logs=False, version_ids=None, batch_size=None)

Fetches an application's request and application logs. (Only logs for requests to the application making the fetch() request can be retrieved.) Returns an iterator that returns RequestLog objects, each of which contains the full log data for a request, both the request logs and any application logs for that request. Raises an InvalidArgumentError if any of the input parameters are not of the correct type.

Arguments:

start_time
The earliest request completion or last-update time that results should be fetched for, in seconds since the Unix epoch.
end_time
The latest request completion or last-update time that results should be fetched for, in seconds since the Unix epoch.
offset
An offset value from a RequestLog object returned in a previous fetch call. May be used to continue a fetch() across multiple HTTP requests, for instance to display pages of results. Subsequent fetch() calls made with the same parameters plus an offset will continue immediately after the RequestLog from which the offset was retrieved.
minimum_log_level
An application log level that serves as a filter on the requests returned. Requests with no application log at or above the specified level will be omitted. This argument takes effect even if include_app_logs is not set to True. In ascending order, the available log levels are:
  • logservice.LOG_LEVEL_DEBUG
  • logservice.LOG_LEVEL_INFO
  • logservice.LOG_LEVEL_WARNING
  • logservice.LOG_LEVEL_ERROR
  • logservice.LOG_LEVEL_CRITICAL
include_incomplete
Specifies whether to include requests that have started but are not yet finished, as a boolean.
include_app_logs
Specifies whether to include application logs, as a boolean. By default, application logs are not returned by logservice.fetch(); you have to invoke it with its include_app_logs parameter set to True.
version_ids
Specifies the version id of the application version to be queried in the fetch call. Currently, you can specify only one version_id per fetch call.
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.