예제 #1
0
func ExampleLog() {
	logger := leveledLogger.New(log.NewLogfmtLogger(os.Stdout))
	logger.Debug("msg", "hello")
	logger = logger.With("context", "foo")
	logger.Error("error", "error message")
	logger.Error("error", "another error message")

	// Output:
	// level=debug msg=hello
	// context=foo level=error error="error message"
	// context=foo level=error error="another error message"
}
예제 #2
0
func TestDoLog(t *testing.T) {
	var (
		buf      = new(bytes.Buffer)
		logger   = leveledLogger.New(log.NewLogfmtLogger(buf))
		expected = "level=info msg=\"message string\" fileline=file:line error=\"some error string\"\n"
		got      string
	)
	logger.Info("msg", "message string", "fileline", "file:line", "error", "some error string")
	got = buf.String()
	if got != expected {
		t.Errorf("Got incorrect log message:\nexpected %q\n but got %q\n", expected, got)
	}
}