zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.41k stars 3.97k forks source link

How to disable go-zero built-in framework log output? #1584

Closed wymli closed 2 years ago

wymli commented 2 years ago

What I want

如何关闭gozero内置的各种日志输出? 我期望stdout只有自己的业务日志输出

What I get

无论是设置mode=pro线上环境,还是logx.Close(),stat.disablelog(),load.disable(),都无法将系统的stat日志,rpc错误日志,以及http的loghandler日志去掉
理论上我期望标准输出只有我自己的日志输出,以便于我做日志收集

Starting server at 0.0.0.0:8888...
// >> 这一行是框架stat日志
2022-02-27T15:10:22.421+08      stat    p2c - conn: 127.0.0.1:9001, load: 1156, reqs: 1
// <<
// >> 这一行是框架打的rpc错误日志
2022-02-27T15:10:22.421+08      info    1.5ms   d1465fed7e8e48d02dc2f504286ffdba        4285f1ed9921a2ce        fail - direct:/127.0.0.1:9001/pb.auth/validateToken -  - rpc error: code = Code(1001) desc = asdf: Code:1001, Msg:服务器内部错误
// <<
// >> 这一行是我的业务日志
2022-02-27T15:10:22+08:00 ERR ../../../common/result/httpResult.go:29 > GET /api/v1/auth/validate req:{} rsp:&{1001 服务器内部错误} err:failed to validate token: rpc error: code = Code(1001) desc = asdf: Code:1001, Msg:服务器内部错误 [service=auth-api] [span_id=0939f60216779380] [trace_id=d1465fed7e8e48d02dc2f504286ffdba]
// << 
// >> 这一行是框架自带的http的loghandler中间件打的日志
2022-02-27T15:10:22.422+08      error   2.5ms   d1465fed7e8e48d02dc2f504286ffdba        0939f60216779380        loghandler.go:191 [HTTP] GET - 500 - /api/v1/auth/validate - [::1]:51640 - curl/7.68.0
GET /api/v1/auth/validate HTTP/1.1
Host: localhost:8888
Accept: */*
User-Agent: curl/7.68.0
// <<

Other

另一个问题, 做日志收集时,stat日志,built-in loghandler日志会被收集吗?


感谢解答!

kevwan commented 2 years ago

logx.DisableStat()

wymli commented 2 years ago

感谢,解决问题~

Issues-translate-bot commented 2 years ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Thanks, problem solved~