How to log messages in GAE go runtime?

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

How to log messages in GAE go runtime?

问题

我正在使用以下简单的代码片段在我的应用程序中记录消息,在本地测试时,我可以看到所有的日志。

然而,当我将应用程序部署到GAE时,我看不到任何应用程序日志。我需要在哪里设置日志属性吗?或者我使用的日志库是错误的吗?

import (
	"log"
)

func Info(logMessage string, v ...interface{}) {
	if v != nil {
		log.Printf("[INFO] "+logMessage, v)
	} else {
		log.Printf("[INFO] " + logMessage)
	}
}
英文:

I am using the following simple code snippet to log messages in my application and during local testing I see all my logs.

However, I do not see any application logs when I deploy the app to GAE. Do I need to set logging properties anywhere? Or am I using the wrong logging library?

import (
	"log"
)

func Info(logMessage string, v ...interface{}) {
	if v != nil {
		log.Printf("[INFO]  "+logMessage, v)
	} else {
		log.Printf("[INFO]  " + logMessage)
	}
}

答案1

得分: 3

你应该使用与Context接口提供的应用引擎日志记录。它提供了几个函数:DebugfInfofWarningfErrorfCriticalf

英文:

You should be using the app engine logging provided with the Context interface.
It provides several Debugf, Infof, Warningf, Errorf, and Criticalf.

答案2

得分: 1

除了deft_code的答案之外:

日志将出现在GAE控制台的日志中,并进行颜色编码。

我给你两行示例代码:

appContext := appengine.NewContext(httpRequest)
appContext.Errorf("无法发送电子邮件:%v", err)
英文:

In addition to deft_code 's answer:

The log will appear in the GAE console's log and color coded.

And I give you 2 lines of sample to start with:

appContext := appengine.NewContext(httpRequest)
appContext.Errorf("Couldn't send email: %v", err)

huangapple
  • 本文由 发表于 2013年9月16日 12:20:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/18820367.html
匿名

发表评论

匿名网友

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

确定