log.Print:打印日志,和fmt包没什么区别,只是加上了上面的日志格式
log.Fatal :会先将日志内容打印到标准输出,接着调用系统的os.exit(1) 接口,退出程序并返回状态 1 。注意,由于是直接调用系统接口退出,defer函数并不会被调用
log.Panic:该函数把日志内容刷到标准错误后调用 panic 函数
对每一类接口其提供了三种调用方式,分别是 “Xxxx 、Xxxxln 、Xxxxf”,基本和fmt中的相关函数类似。
log 结构的定义如下:
type Logger struct {
mu sync.Mutex // ensures atomic writes; protects the following fields
prefix string // prefix to write at beginning of each line
flag int // properties
out io.Writer // destination for output
buf []byte // for accumulating text to write
}
const (
Ldate = 1 << iota // the date in the local time zone: 2009/01/23
Ltime // the time in the local time zone: 01:23:23
Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime.
Llongfile // full file name and line number: /a/b/c/d.go:23
Lshortfile // final file name element and line number: d.go:23. overrides Llongfile
LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone
LstdFlags = Ldate | Ltime // initial values for the standard logger
)