ThePiachu
ThePiachu

Reputation: 9175

GAE Golang - log.Print()?

Where can one read logs created by calling function:

log.Print("Message")

The tab "Logs" under Main seems to only display information about what URLs were called, but without any debug information that would be displayed by the application.

Upvotes: 20

Views: 8234

Answers (3)

Chunliang Lyu
Chunliang Lyu

Reputation: 1750

If you are using the new App Engine package google.golang.org/appengine, in the README:

  • Logging methods that were on appengine.Context are now functions in google.golang.org/appengine/log

So you should use

c := appengine.NewContext(r)
log.Infof(c, "Requested URL: %v", r.URL)

Upvotes: 7

proppy
proppy

Reputation: 10504

As described in the documentation, you should use the Context interface to log instead of log, if you want your logs to show up in the console.

c := appengine.NewContext(r)
c.Infof("Requested URL: %v", r.URL)

Upvotes: 30

Mafan W
Mafan W

Reputation: 17

The same context object must be passed around in other method calls. Here is an example:

func handleSign(w http.ResponseWriter, r *http.Request) {   
    c := appengine.NewContext(r)
    if err := r.ParseForm(); err != nil {
        writeError(c, err)
        return
    }
}

func writeError(c appengine.Context, err os.Error) {
    c.Errorf("%v", err)
} 

Upvotes: 0

Related Questions