Skip to content

Instantly share code, notes, and snippets.

@freeformz
Last active January 31, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freeformz/3334b5a88602c08927b420de665224dd to your computer and use it in GitHub Desktop.
Save freeformz/3334b5a88602c08927b420de665224dd to your computer and use it in GitHub Desktop.
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