Why fmt.Println does not work in Google app

I created a simple web application using Google App Engine and golang. in the code below, I use fmt.Println twice to print something for debugging purposes. I have no problem running the application. everything works except nothing is printed 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) } 
+6
source share
2 answers

In a real appengine environment, you cannot output anything to stdout.
The Appengine context gives you access to the log (which you can check on the appengine administration page and on the console game pad).

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

More details: https://developers.google.com/appengine/docs/go/reference#Context

+10
source

standard i / o Or a communication error is used with the application server used by devleoper. In a production system, it makes no sense to use standard I / O. In production systems, a journal is used to track results. There are some limitations in the engine application. like fmt, connector, etc.

It is always better to use the log when testing or running a program on a remote server.

0
source

Source: https://habr.com/ru/post/970668/


All Articles