From 68f326fa8629521804d0426ce0bea04fc3a6a2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=20G=C3=B3mez=20Escandell?= Date: Wed, 15 Nov 2023 11:26:14 +0100 Subject: [PATCH] Print Landscape logs on failure Or any other component which ends up using slogs --- end-to-end/utils_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/end-to-end/utils_test.go b/end-to-end/utils_test.go index f1369714a..a1aa0435c 100644 --- a/end-to-end/utils_test.go +++ b/end-to-end/utils_test.go @@ -8,6 +8,7 @@ import ( "fmt" "io/fs" "log" + "log/slog" "os" "os/exec" "path/filepath" @@ -48,6 +49,16 @@ func testSetup(t *testing.T) { log.Printf("Cleanup: %v", err) } }) + + var out bytes.Buffer + h := slog.NewTextHandler(&out, &slog.HandlerOptions{Level: slog.LevelDebug}) + slog.SetDefault(slog.New(h)) + + t.Cleanup(func() { + if t.Failed() { + fmt.Printf("==== SLOGS ====\n%s", out.String()) + } + }) } //nolint:revive // testing.T must precede the context