2014-06-11 03:25

为什么fmt.Println在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)

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

    postList := []dto.Post{}

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


        postList = append(postList, newpost)

    page := dto.PageData{Title: "Home", Posts: postList}
    templates.ExecuteTemplate(w, "index", page)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • doulong2782 doulong2782 7年前

    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

    点赞 评论 复制链接分享
  • donk68254 donk68254 7年前

    standard i/o Or Error is used communicate with app server used by the devleoper. In production system there's no meaning of using standard i/o. In production systems log is used to track the results. In app engine there's some limitations. like fmt, socket etc.

    Its always better to use log when testing or running program in remote server.

    点赞 评论 复制链接分享