只能从Google App Engine golang应用程序访问请求日志

I have a GAE golang application that has logging statements that look something like:

func LogDebugMessage(req *http.Request) {
  context := appengine.NewContext(req)
  c.Debugf("#%d Debugging Here.", 1)
}

How can I access the logging messages generated by the c.Debugf call?

The appcfg.py request_logs and GAE console (https://console.developers.google.com/project/.../logs) both appear to only have HTTP request logs.

Is there another tool to request logs generated by the GAE context?

There are 2 kinds of logs: Request logs which are generated automatically by the platform for all requests and contains request details (like timestamp, client ip, user agent, status codes, serving time, instance id etc.) and Application logs which are the result of context.Debugf(), context.Warningf(), context.Infof(), context.Errorf() and context.Criticalf() method calls.

Application logs are attached to (or associated with) requests (request log records), requests from which they were called (during serving those requests).

Request (and application) logs can be viewed on the Logs page of the Admin console or on the Developer console. Both the Admin console and the Developer console display both Request and Application log records. Note that on both the Admin and Developer console you have to click on the log records to expand them. Once you expand a request log, all application log records will be displayed that were done from that request.

If you want to download application logs as well, you can specify the --include_all parameter to the appcfg.py tool.

Programatically you can query the request logs, see Logs Go API Overview for more details. Here is the Log package reference.

When you query request logs, the result are log.Record values. This is a struct which contains an AppLogs field which is a slice of log.AppLog. This AppLog type (it's also a struct) descirbes an application log made by e.g. a context.Debugf() call.

The AppLog type looks like this:

type AppLog struct {
    Time    time.Time
    Level   int
    Message string
}

The Message is the string result of the formatted log message.

Here is an example how to query the log records including Application logs:

c := appengine.NewContext(r)
query := &log.Query{
    AppLogs:  true,
    Versions: []string{"1"},
}

for results := query.Run(c); ; {
    record, err := results.Next()
    if err == log.Done {
        c.Infof("Done processing results")
        break
    }
    if err != nil {
        c.Errorf("Failed to retrieve next log: %v", err)
        break
    }
    // Do something with record
    // Process Application logs:

    for _, ap := range record.AppLogs {
        msg := ap.Message
        // msg is an application log text message
    }
}