Google App Engine

Logs Java API Overview

Python |Java |PHP |Go
  1. Overview
  2. Getting log data
  3. Quotas and limits


The Logs API provides access to the application and request logs for your application. (You can also access the logs for your application in the UI by clicking Logs in the left navigation pane in the Admin Console.)

Log categories: request logs and app logs

There are two categories of log data: request logs and application logs. A request log is written for each request handled by your app, and contains information such as the app ID, HTTP version, and so forth. For a complete list of available properties for request logs, see RequestLogs.

Each request log contains a list of application logs (AppLogLine) associated with that request, returned in the RequestLogs.getAppLogLines() method. Each app log contains the time the log was written, the log message, and the log level.

Getting log data

The general process of getting logs is as follows:

  1. Use LogQuery to specify which logs to return.
  2. Use LogServiceFactory.getLogService() to create the LogService
  3. Invoke LogServiceFactory.getLogService().fetch() to return an iterator for the request logs.
  4. In each iteration, for each RequestLogs, process the request properties as desired.
  5. Optionally, use RequestLogs.getAppLogLines() to get the list of app logs (AppLogLine) associated with this request.
  6. If you retrieved the app logs list, for each AppLogLine, process the property data as desired.

Sample code

The following sample displays 5 request logs at at time, along with their application logs. It lets you cycle through each set of 5 logs using a Next link.

package testapp;

import javax.servlet.http.*;
import java.util.Calendar;

// Get request logs along with their app log lines and display them 5 at
// a time, using a Next link to cycle through to the next 5.
public class TestAppServlet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
         throws IOException {

    PrintWriter writer = resp.getWriter();
    // We use this to break out of our iteration loop, limiting record
    // display to 5 request logs at a time.
    int limit = 5;

    // This retrieves the offset from the Next link upon user click.
    String offset = req.getParameter("offset");

    // We want the App logs for each request log
    LogQuery query = LogQuery.Builder.withDefaults();

    // Set the offset value retrieved from the Next link click.
    if (offset != null) {

    // This gets filled from the last request log in the iteration
    String lastOffset = null;
    int i = 0;

    // Display a few properties of each request log.
    for (RequestLogs record : LogServiceFactory.getLogService().fetch(query)) {
      writer.println("<br />REQUEST LOG <br />");
      Calendar cal = Calendar.getInstance();
      cal.setTimeInMillis(record.getStartTimeUsec() / 1000);

      writer.println("IP: " + record.getIp()+"<br />");
      writer.println("Method: " + record.getMethod()+"<br />");
      writer.println("Resource " + record.getResource()+"<br />");
      writer.println(String.format("<br />Date: %s", cal.getTime().toString()));

      lastOffset = record.getOffset();

      // Display all the app logs for each request log.
      for (AppLogLine appLog : record.getAppLogLines()) {
        writer.println("<br />"+ "APPLICATION LOG" +"<br />");
        Calendar appCal = Calendar.getInstance();
        appCal.setTimeInMillis(appLog.getTimeUsec() / 1000);
        writer.println(String.format("<br />Date: %s",
        writer.println("<br />Level: "+appLog.getLogLevel()+"<br />");
        writer.println("Message: "+ appLog.getLogMessage()+"<br /> <br />");
      } //for each log line

      if (++i >= limit) {
    } // for each record

    // When the user clicks this link, the offset is processed in the
    // GET handler and used to cycle through to the next 5 request logs.
    writer.println(String.format("<br><a href=\"/?offset=%s\">Next</a>",
  }  // end doGet
} //end class

In the sample, notice that the GET handler expects to be re-invoked by the user clicking on the Next link, and so it extracts the offset param, if present. That offset is used in the subsequent re-invocation of LogServiceFactory.getLogService().fetch() to "page through" each group of 5 request logs. There is nothing special about the number 5; it can be anything you want.

Quotas and limits

Your application is affected by the following logs-related quotas:

  • Logs data retrieved via the Logs API.
  • Log storage, also called logs retention.

Quota for data retrieved

The first 100 megabytes of logs data retrieved per day via the Logs API calls are free. After this amount is exceeded, no further Logs API calls will succeed unless billing is enabled for your app. If billing is enabled for your app, data in excess of 100 megabytes results in charges of $0.12/GB per gigabye.

Logs storage

You can control how much log data your application stores by means of its log retention settings in the Admin Console. By default, logs are stored for an application free of charge with the following per-application limits: a maximum of 1 gigabyte for a maximum of up to 90 days. If either limit is exceeded, more recent logs will be shown and older logs will be deleted to stay within the size limit. Logs older than the maximum retention time are also deleted.

If your app has billing enabled, you can pay for higher log size limits by specifying the desired maximum log size in gigabytes in the Admin Console. You can also set the retention time by specifying the desired number of days to keep logs, up to a maximum of 365 days. The cost of this extra log storage is $0.026 per gigabyte utilized per month.

Limit Amount Cost past free threshold
Maximum days storage per log 90 days free, 365 days if paid $0.026 per gigabyte utilized per month
Maximum total logs storage 1 gigabyte free, unlimited if paid $0.026 per gigabyte utilized per month

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.