Last active
January 31, 2017 16:36
-
-
Save freeformz/3334b5a88602c08927b420de665224dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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