nacos-group / nacos-sdk-go

Nacos client in Golang
Apache License 2.0
1.12k stars 337 forks source link

Fix InitLogger just no work #759

Closed dingyang666 closed 3 months ago

dingyang666 commented 3 months ago

https://github.com/nacos-group/nacos-sdk-go/pull/722 这个 pr 导致 InitLogger 无法工作,原因是 init 创建了一个 logger 导致 InitLogger 中的 if logger != nil 永远是 true,见 https://github.com/nacos-group/nacos-sdk-go/issues/747

碰巧 init 中创建的 logger 是 debug 级别,会在线上输出大量日志,更新后日志相关成本激增 image

改用 sync.Once 保证只创建一次,在 InitLogger 不失效的同时,满足 https://github.com/nacos-group/nacos-sdk-go/pull/722 老哥大量创建和销毁客户端的奇怪需求

CLAassistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.

dingyang666 commented 3 months ago

建议直接去掉 logger != nil 的逻辑,这里应该允许重复创建logger, 大量创建使用不当,不应该在sdk的考虑范围内

done