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() }
// 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() } }
// 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() } }
// 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() } }
// 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() } }
// 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() } }
// 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() } }
// 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() } }
// 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() } }
// 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' }