Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't fmt.Println work in Google app engine

I built a simple web app using google app engine and golang. in code below, I use fmt.Println twice to print out somehting for debugging purpose. I have no problem running the app. everything works except nothing print out on the terminal.

func HomeHandler(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    q := datastore.NewQuery("Post").Ancestor(goblogKey(c)).Order("-CreatedOn").Limit(10)

    //posts := make([]entity.Post, 0, 10)
    var posts []entity.Post

    if _, err := q.GetAll(c, &posts); err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    fmt.Println(string(len(posts)) + "...........")

    postList := []dto.Post{}

    for _, val := range posts {
        newpost := dto.Post{
            Post:     val,
            BodyHTML: template.HTML(val.Body),
        }

        fmt.Println(val.Title)

        postList = append(postList, newpost)
    }

    page := dto.PageData{Title: "Home", Posts: postList}
    templates.ExecuteTemplate(w, "index", page)
}
like image 218
qinking126 Avatar asked Jun 11 '14 03:06

qinking126


1 Answers

In the real appengine enviroment you can't se anything output to stdout.
Appengine context give you away to log (that you can check in you appengine admin's page and in console playground).

func HomeHandler(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    c.Debugf("The message: %s", "foo")
    ...

Read more: https://developers.google.com/appengine/docs/go/reference#Context

like image 175
nvcnvn Avatar answered Sep 21 '22 17:09

nvcnvn