GAE Golang – log.Print()?

huangapple go评论90阅读模式
英文:

GAE Golang - log.Print()?

问题

在哪里可以阅读通过调用函数创建的日志:

log.Print("Message")

主界面下的“日志”选项卡似乎只显示有关调用的URL的信息,但没有显示应用程序显示的任何调试信息。

英文:

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.

答案1

得分: 30

根据文档的描述,如果您希望日志显示在控制台中,应该使用Context接口来记录日志,而不是使用log

c := appengine.NewContext(r)
c.Infof("请求的URL:%v", r.URL)
英文:

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)

答案2

得分: 7

如果您正在使用新的App Engine包google.golang.org/appengine,在README中:

> * appengine.Context上的日志记录方法现在是google.golang.org/appengine/log中的函数

所以您应该使用

c := appengine.NewContext(r)
log.Infof(c, "请求的URL:%v", r.URL)
英文:

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)

答案3

得分: 0

在其他方法调用中必须传递相同的上下文对象。
以下是一个示例:

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)
}
英文:

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)
} 

huangapple
  • 本文由 发表于 2012年1月31日 11:31:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/9074012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定