當前位置: 首頁>>代碼示例>>Golang>>正文


Golang kiwi.SinkTo函數代碼示例

本文整理匯總了Golang中github.com/grafov/kiwi.SinkTo函數的典型用法代碼示例。如果您正苦於以下問題:Golang SinkTo函數的具體用法?Golang SinkTo怎麽用?Golang SinkTo使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了SinkTo函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	// Bind a new logger to a variable. You may create any number of loggers.
	ctx := kiwi.New()

	// For starting write ctx records to some writer output should be initialized.
	out := kiwi.SinkTo(os.Stdout, kiwi.UseLogfmt()).Start()

	// setup context of the logger
	ctx.With("userID", 1000, "host", "local", "startedAt", time.Now())

	// This record will be supplemented by startedAt value of time.Now().String()
	ctx.Add("sample", 1).Log()

	// This record also will be supplemented by the same value of the time.
	// Because context value evalueted when it was added by ctx.With().
	ctx.Add("sample", 2).Log()

	// You can provide deferred evaluation of context or ctx values if you add them wrapped
	// with func() interface{}, where interface should be one of scalar golang types.
	ctx.With("currentTime", func() string { return time.Now().String() })

	// Get previously saved context for use in the application.
	// They were keep as is without conversion to strings.
	currentContext := ctx.GetContext()
	fmt.Printf("some of the context values are: %d, %s\n", currentContext["userID"], currentContext["host"])

	// These records will be output each its own currentTime value because currentTime will
	// be evaluated on each Log() call.
	ctx.Add("sample", 3).Log()
	ctx.Add("sample", 4).Log()
	out.Flush()
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:32,代碼來源:main.go

示例2: BenchmarkLevelsKiwiTypedHelpers_JSON

func BenchmarkLevelsKiwiTypedHelpers_JSON(b *testing.B) {
	buf := &bytes.Buffer{}
	b.ResetTimer()
	l := kiwi.New()
	l.With("_n", "bench", "_p", pid)
	l.WithTimestamp(time.RFC3339)
	kiwi.LevelName = "l"
	out := kiwi.SinkTo(buf, kiwi.UseJSON()).Start()
	for i := 0; i < b.N; i++ {
		l.AddPairs(
			kiwi.AsInt("key", 1),
			kiwi.AsFloat64("key2", 3.141592),
			kiwi.AsString("key3", "string"),
			kiwi.AsBool("key4", false)).Debug()
		l.AddPairs(
			kiwi.AsInt("key", 1),
			kiwi.AsFloat64("key2", 3.141592),
			kiwi.AsString("key3", "string"),
			kiwi.AsBool("key4", false)).Info()
		l.AddPairs(
			kiwi.AsInt("key", 1),
			kiwi.AsFloat64("key2", 3.141592),
			kiwi.AsString("key3", "string"),
			kiwi.AsBool("key4", false)).Warn()
		l.AddPairs(
			kiwi.AsInt("key", 1),
			kiwi.AsFloat64("key2", 3.141592),
			kiwi.AsString("key3", "string"),
			kiwi.AsBool("key4", false)).Error()
	}
	b.StopTimer()
	out.Close()
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:33,代碼來源:loggers_benchmark_json_test.go

示例3: TestGlobalLogger_LogFloatValue_Logfmt

// Test logging of float value in default (scientific) format.
func TestGlobalLogger_LogFloatValue_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.Log("k", 3.14159265359)

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "k=3.14159265359e+00" {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:global-logger_test.go

示例4: TestGlobalLogger_LogNegativeIntValue_Logfmt

// Test logging of negative integer value.
func TestGlobalLogger_LogNegativeIntValue_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.Log("k", 123)

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "k=123" {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:global-logger_test.go

示例5: TestGlobalLogger_LogBytesValue_Logfmt

// Test logging of byte array.
func TestGlobalLogger_LogBytesValue_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.Log("k", []byte("The sample string with a lot of spaces."))

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "k=\"The sample string with a lot of spaces.\"" {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:global-logger_test.go

示例6: TestGlobalLogger_LogNumericKey_Logfmt

// Test logging of the numeric key.
func TestGlobalLogger_LogNumericKey_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.Log(123, "The sample value.")

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "123=\"The sample value.\"" {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:global-logger_test.go

示例7: TestGlobalLogger_LogKeyWithSpaces_Logfmt

// Test logging of the key with spaces.
func TestGlobalLogger_LogKeyWithSpaces_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.Log("key with spaces", "The sample value.")

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "\"key with spaces\"=\"The sample value.\"" {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:global-logger_test.go

示例8: TestGlobalLogger_LogComplexValue_Logfmt

// Test logging of complex number.
func TestGlobalLogger_LogComplexValue_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.Log("k", .12345E+5i, "k2", 1.e+0i)

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "k=(0.000000+12345.000000i) k2=(0.000000+1.000000i)" {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:global-logger_test.go

示例9: TestGlobalLogger_LogBoolValue_Logfmt

// Test logging of boolean value.
func TestGlobalLogger_LogBoolValue_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.Log("k", true, "k2", false)

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "k=true k2=false" {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:global-logger_test.go

示例10: BenchmarkLevelsKiwiGlobal_JSON

func BenchmarkLevelsKiwiGlobal_JSON(b *testing.B) {
	buf := &bytes.Buffer{}
	b.ResetTimer()
	out := kiwi.SinkTo(buf, kiwi.UseJSON()).Start()
	for i := 0; i < b.N; i++ {
		kiwi.Log("t", time.Now().Format(time.RFC3339), "l", "debug", "_n", "bench", "_p", pid, "key", 1, "key2", 3.141592, "key3", "string", "key4", false)
		kiwi.Log("t", time.Now().Format(time.RFC3339), "l", "info", "_n", "bench", "_p", pid, "key", 1, "key2", 3.141592, "key3", "string", "key4", false)
		kiwi.Log("t", time.Now().Format(time.RFC3339), "l", "warn", "_n", "bench", "_p", pid, "key", 1, "key2", 3.141592, "key3", "string", "key4", false)
		kiwi.Log("t", time.Now().Format(time.RFC3339), "l", "error", "_n", "bench", "_p", pid, "key", 1, "key2", 3.141592, "key3", "string", "key4", false)
	}
	b.StopTimer()
	out.Close()
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:13,代碼來源:loggers_benchmark_json_test.go

示例11: TestGlobalLogger_LogTimeValue_Logfmt

// Test logging of time literal.
func TestGlobalLogger_LogTimeValue_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()
	value := time.Now()
	valueString := value.Format(kiwi.TimeLayout)

	kiwi.Log("k", value)

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != fmt.Sprintf("k=%s", valueString) {
		println(output.String())
		t.Fail()
	}
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:15,代碼來源:global-logger_test.go

示例12: TestGlobalLogger_LogFixedFloatValue_Logfmt

// Test logging of float value in fixed format.
func TestGlobalLogger_LogFixedFloatValue_Logfmt(t *testing.T) {
	output := bytes.NewBufferString("")
	out := kiwi.SinkTo(output, kiwi.UseLogfmt()).Start()

	kiwi.FloatFormat = 'f'
	kiwi.Log("k", 3.14159265359)

	out.Flush().Close()
	if strings.TrimSpace(output.String()) != "k=3.14159265359" {
		println(output.String())
		t.Fail()
	}
	// Turn back to default format.
	kiwi.FloatFormat = 'e'
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:16,代碼來源:global-logger_test.go

示例13: BenchmarkLevelsKiwiTypedHelpersComplex_JSON

func BenchmarkLevelsKiwiTypedHelpersComplex_JSON(b *testing.B) {
	buf := &bytes.Buffer{}
	b.ResetTimer()
	l := kiwi.New()
	l.With("_n", "bench", "_p", pid)
	l.WithTimestamp(time.RFC3339)
	kiwi.LevelName = "l"
	out := kiwi.SinkTo(buf, kiwi.UseJSON()).Start()
	for i := 0; i < b.N; i++ {
		l.AddPairs(kiwi.AsInt("key", 1), kiwi.AsStringer("obj", testObject)).Debug()
		l.AddPairs(kiwi.AsInt("key", 1), kiwi.AsStringer("obj", testObject)).Info()
		l.AddPairs(kiwi.AsInt("key", 1), kiwi.AsStringer("obj", testObject)).Warn()
		l.AddPairs(kiwi.AsInt("key", 1), kiwi.AsStringer("obj", testObject)).Error()
	}
	b.StopTimer()
	out.Close()
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:17,代碼來源:loggers_benchmark_json_test.go

示例14: BenchmarkLevelsKiwi_JSON

func BenchmarkLevelsKiwi_JSON(b *testing.B) {
	buf := &bytes.Buffer{}
	b.ResetTimer()
	l := kiwi.New()
	l.With("_n", "bench", "_p", pid)
	l.WithTimestamp(time.RFC3339)
	kiwi.LevelName = "l"
	out := kiwi.SinkTo(buf, kiwi.UseJSON()).Start()
	for i := 0; i < b.N; i++ {
		l.Debug("key", 1, "key2", 3.141592, "key3", "string", "key4", false)
		l.Info("key", 1, "key2", 3.141592, "key3", "string", "key4", false)
		l.Warn("key", 1, "key2", 3.141592, "key3", "string", "key4", false)
		l.Error("key", 1, "key2", 3.141592, "key3", "string", "key4", false)
	}
	b.StopTimer()
	out.Close()
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:17,代碼來源:loggers_benchmark_json_test.go

示例15: BenchmarkLevelsKiwiComplex_JSON

func BenchmarkLevelsKiwiComplex_JSON(b *testing.B) {
	buf := &bytes.Buffer{}
	b.ResetTimer()
	l := kiwi.New()
	l.With("_n", "bench", "_p", pid)
	l.WithTimestamp(time.RFC3339)
	kiwi.LevelName = "l"
	out := kiwi.SinkTo(buf, kiwi.UseJSON()).Start()
	for i := 0; i < b.N; i++ {
		l.Debug("key", 1, "obj", testObject)
		l.Info("key", 1, "obj", testObject)
		l.Warn("key", 1, "obj", testObject)
		l.Error("key", 1, "obj", testObject)
	}
	b.StopTimer()
	out.Close()
}
開發者ID:grafov,項目名稱:kiwi,代碼行數:17,代碼來源:loggers_benchmark_json_test.go


注:本文中的github.com/grafov/kiwi.SinkTo函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。