INNER CODE UNIT · Go

TestStdLogRedirectsToZap

openkruise/kruise-game · main_test.go:161

func TestStdLogRedirectsToZap(t *testing.T) {
	var buf bytes.Buffer
	opts, _ := newTestOptions(t, &buf, "--log-format=json")
	logger := zap.New(zap.UseFlagOptions(&opts.ZapOptions))
	if zl, ok := logger.GetSink().(zapr.Underlier); ok {
		if u := zl.GetUnderlying(); u != nil {
			_ = gozap.ReplaceGlobals(u)
			_ = gozap.RedirectStdLog(u)
		}
	}
	buf.Reset()
	log.Println("hello")

	lines := bytes.Split(bytes.TrimSpace(buf.Bytes()), []byte("\n"))
	if len(lines) != 1 {
		t.Fatalf("expected single line JSON, got %d lines: %q", len(lines), buf.String())
	}
	var m map[string]interface{}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…