Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Logs Go API Overview

  1. Overview
  2. Getting log data
  3. Quotas and limits

Overview

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 Record .

Each request log contains a list of application logs ( AppLog ) associated with that request, returned in the Record.AppLog field. 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. Create a Query value that specifies which logs to return.
  2. Call the Run method to obtain a Result iterator.
  3. Repeatedly call the Next method to obtain Record values.

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 logs using a Next link.

// This sample gets the app displays 5 log Records at a time, including all
// AppLogs, with a Next link to let the user page through the results using the
// Record's Offset property.
package app

import (
        "encoding/base64"
        "html/template"
        "net/http"

        "appengine"
        "appengine/log"
)

func init() {
        http.HandleFunc("/", handler)
}

const recordsPerPage = 5

func handler(w http.ResponseWriter, r *http.Request) {
        c := appengine.NewContext(r) 

        // Get the incoming offset param from the Next link to advance through
        // the logs. (The first time the page is loaded there won't be any offset.)
        offset, _ := base64.URLEncoding.DecodeString(r.FormValue("offset"))

        // Set up a data structure to pass to the HTML template.
        var data struct {
                Records []*log.Record
                Offset  string // base-64 encoded string
        }

        // Set up a log.Query.
        query := &log.Query{Offset: offset, AppLogs: true}

        // Run the query, obtaining a Result iterator.
        res := query.Run(c)

        // Iterate through the results populating the data struct.
        for i := 0; i < recordsPerPage; i++ {
                rec, err := res.Next()
                if err == log.Done {
                        break
                }
                data.Records = append(data.Records, rec)
                if i == recordsPerPage-1 {
                        data.Offset = base64.URLEncoding.EncodeToString(rec.Offset)
                }
        }

        // Render the template to the HTTP response.
        if err := tmpl.Execute(w, data); err != nil {
                c.Errorf("Rendering template: %v", err)
        }
}

var tmpl = template.Must(template.New("").Parse(`
	{{range .Records}}
		<h2>Request Log</h2>
		<p>{{.EndTime}}: {{.IP}} {{.Method}} {{.Resource}}</p>
		{{with .AppLogs}}
			<h3>App Logs:</h3>
			<ul>
			{{range .}}
				<li>{{.Time}}: {{.Message}}</li>
			<{{end}}
			</ul>
		{{end}}
	{{end}}
	{{with .Offset}}
		<a href="?offset={{.}}">Next</a>
	{{end}}
`))

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 log.Query.Run 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.

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

The development server and Logs API

By default, logs are stored in memory only in the development server and are accessible if you wish to test the Logs API feature. If you wish to persist logs from the development server to disk at the default location /tmp/dev_appserver.logs , supply the --persist_logs command line option as follows:

dev_appserver.py --persist_logs your-app-directory

If you wish to persist the logs from the development server to disk at a location of your own choosing, supply the desired path and filename to the --logs_path command line option as follows:

dev_appserver.py --logs_path=your-path/your-logfile-name your-app-directory

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.