Skip to content

Instantly share code, notes, and snippets.

@freeformz
Last active Jan 31, 2017
Embed
What would you like to do?
package level // github.com/go-kit/kit/log/level
type LogLevels int
const (
Debug LogLevels = iota
Info
Warn
Err
)
// main.go....
func main() {
var logger log.Logger
logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
// A (no leveled logging)
logger.Log(Level.Debug, "foo", "bar")
// level=debug foo=bar
// B
l = logger.WithFilter(level.Filter(level.Debug)) // WithFilter returns a log.Logger
l.Log(level.Debug, "foo", "bar")
// foo=bar
// C
l = logger.WithFilter(level.Filter(level.Info))
l.Log(Level.Debug, "foo","bar")
// <nothing>
// D
l = logger.With(Level.Info)
l = l.WithFilter(level.Filter(level.Info))
// pass l to a library/struct that doesn't use levels to fix all logs from that library to Info
// Assuming that that library/struct eventually starts to use levels (you submitted a PR right?)
// This still works as the locally applied levels could take precedence over the global as the global
// still applies the filter.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment