在Go中禁用第三方库的日志记录。

huangapple go评论83阅读模式
英文:

Disable logs from 3rd party libraries in Go

问题

我想禁用自定义日志包中的各种第三方库的日志记录。我无法直接修改这些库或者日志包。我已经查看了https://stackoverflow.com/questions/38831816/disable-logging-for-3rd-party-library,其中建议重新定义os.Stderr为自定义的io.Writer。我该如何实现这里描述的方法:https://stackoverflow.com/a/38832115/18024985?

英文:

I want to disable logs from various 3rd party libraries which a custom log package. I'm not able to modify the libraries directly or the log package. I've already looked at https://stackoverflow.com/questions/38831816/disable-logging-for-3rd-party-library which suggests to redefine os.Stderr as a custom io.Writer. How do I implement the approach described here: https://stackoverflow.com/a/38832115/18024985?

答案1

得分: 2

你所指的问题描述了一个与你的情况不同的情况,其中使用了自定义的日志记录器。在你的情况下,使用标准的日志记录器,你应该使用log.SetOutput而不是重定向os.Stderr

英文:

The question you have pointed to describes a different situation from yours, where a custom logger is being used. In your case, with the standard logger, you should use log.SetOutput rather than redirecting os.Stderr.

huangapple
  • 本文由 发表于 2022年6月30日 07:23:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/72808813.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定