背景:ent开始debug模式后,可以输出日志,但是我们想为ent接入zerolog,该怎么做呢?
一、引入zerolog
go get -u github.com/rs/zerolog
二、自定义zerolog配置
customLog := func(args ...any) { str := fmt.Sprintf("%v", args) fmt.Println(str) logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() logger.Info().Str("time", time.Now().String()).Msg(str) }
三、为ent日志对接zerolog
client, err := ent.Open("mysql", "root:dev@123456@tcp(localhost:3306)/test?parseTime=True", ent.Log(customLog), ent.Debug())
标签:fmt,zerolog,ent,str,go,日志 From: https://www.cnblogs.com/jamstack/p/17743871.html