本文介绍了如何在golang中实现基于级别的日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在golang中有没有很好的包装器可用于基于级别的日志记录?
如果不是,我应该如何去实现一个自己?
我想要的非常简单。我想要一些函数,例如
pre $ log.Error()
log.Info()
等等,它们将输出显示到标准输出并将它们保存在日志文件中(基于作为命令行给予程序的级别论据)。
如何实现这个包装器?
解决方案
现在的答案已经很老了: / p>
- - 比其他地方小
- - 用于许多流行项目,如Docker
- - 来自Google,在Go中实现其C ++ glog库
Is there any good wrapper available for level based logging in golang?If not, how should I go about implementing one myself?
What I want is pretty simple. I want a few functions e.g.
log.Error()
log.Info()
etc that display their outputs to stdout as well as save these in a log file (based on the level given to the program as commandline argument).How do I implement this wrapper?
解决方案
Some more suggestions, now that the existing answers are quite old:
- https://github.com/op/go-logging - smaller than the other here
- https://github.com/Sirupsen/logrus - used in many popular projects such as Docker
- https://github.com/inconshreveable/log15
- https://github.com/golang/glog - from Google, implementation of their C++ glog library in Go
这篇关于如何在golang中实现基于级别的日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!