#golang# uber日志库zap配置示例
简单示例,格式化输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package main import ( "go.uber.org/zap" "time" ) func main() { // zap.NewDevelopment 格式化输出 logger, _ := zap.NewDevelopment() defer logger.Sync() logger.Info("无法获取网址", zap.String("url", "http://www.baidu.com"), zap.Int("attempt", 3), zap.Duration("backoff", time.Second), ) } #输出结果 #2019-01-02T15:01:13.923+0800 INFO spikeProxy/main.go:17 failed to fetch URL {"url": "http://www.baidu.com", "attempt": 3, "backoff": "1s"} |
json序列化输出:…