当前位置: 首页>>代码示例>>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;未经允许,请勿转载。