go-zero日志的优化

go-zero日志的优化

在你生成的 etc/xxx.yaml 文件下添加Log的配置

Name: auth
Host: 0.0.0.0
Port: 8888
Log:
  ServiceName: auth
  Encoding: plain
  Stat: false
  TimeFormat: 2006-01-02 15:04:05

这个Log的源头就在 internal/config/config.go 的 rest.RestConf 结构体之中,找到 Log 为 logx.LogConf

优化前:

{"@timestamp":"2024-07-19T16:47:06.034+08:00","caller":"stat/metrics.go:210","content":"(auth) - qps: 0.0/s, drops: 0, avg time: 0.0ms, med: 0.0ms, 90th: 0.0ms, 99th: 0.0ms, 99.9th: 0.0ms","level":"stat"}

优化后:

2024-07-19 16:52:23      info   [HTTP]  200  -  POST  /api/auth/login - [::1]:57125 - Apifox/1.0.0 (https://apifox.com) caller=handler/loghandler.go:147        trace=90bd548212e2c5066abf202384b6f113  span=7e1e224a47cd0782    duration=0.3ms
posted @ 2025-04-09 10:36  小依昂阳  阅读(20)  评论(0)    收藏  举报