How to implement level based logging in golang?
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
- https://github.com/go-kit/kit/tree/master/log focused on "structured logging" which is better for tools to consume
- https://github.com/uber-go/zap - "blazing fast"
Take a look at http://cgl.tideland.biz and there at the package "applog". It's working that way.
PS: The whole CGL is currently reworked and will soon be released with new features, but under a different name. ;)
- Uber-go/Zap: Fast, structured, leveled logging in Go
- Logrus: Structured, pluggable logging for Go. (JSON and text formatting)
Both libraries have level hooks also, which is a very interesting feature. Hooks can be registered for particular log levels. So for example any error(logged using log.Error()
) occurs you can report to some monitoring tool etc.