Skip to content

Log

格式化

package main

import "log"

func main() {
    log.SetFlags(log.Ldate | log.Ltime | log.Llongfile)
    log.Fatalln("hello world")
}

zap

log.go
package v7

import "go.uber.org/zap"

var sugar *zap.SugaredLogger

func init() {
    logger, _ := zap.NewDevelopment()
    defer logger.Sync() // flushes buffer, if any
    sugar = logger.Sugar()
}
json 输出
sugar.Infow("msg","key","val","key1","val1",)