Skip to content
KerwinKoo edited this page Jan 25, 2016 · 12 revisions

日志

Goa的日志格式固定,如测试代码的mount日志:

INFO[01-25|09:56:34] mount      app=API ctrl=Operands action=Add route="GET /add/:left/:right"

依次为:

  • 日志类型
  • 日志时间
  • 行为名称
  • 日志内容

其中日志内容是以key=value的形式存在。

Logger接口的实现:

// A Logger writes key/value pairs to a Handler
type Logger interface {
	// New returns a new Logger that has this logger's context plus the given context
	New(ctx ...interface{}) Logger

	// SetHandler updates the logger to write records to the specified handler.
	SetHandler(h Handler)

	// Log a message at the given level with context key/value pairs
	Debug(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
	Crit(msg string, ctx ...interface{})
}

具体调用方法为:

service.Info("mount", "ctrl", "Operands", "action", "Add", "route", "GET /add/:left/:right")

第一个是日志的名字,其他必须是成对出现,每对为对应的key=value。

[[TOC]]

Clone this wiki locally