From 4aa7fd37de11073991fea99205a9411367069d80 Mon Sep 17 00:00:00 2001 From: Abhishek Ghosh Date: Tue, 18 Mar 2025 12:45:59 +0530 Subject: [PATCH 1/4] Add flag to prefix log lines with log source (task and step name) by default Signed-off-by: Abhishek Ghosh --- pkg/cmd/pipeline/logs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/cmd/pipeline/logs.go b/pkg/cmd/pipeline/logs.go index d7b6cb26d5..fe59e300d3 100644 --- a/pkg/cmd/pipeline/logs.go +++ b/pkg/cmd/pipeline/logs.go @@ -97,6 +97,7 @@ Show logs for given Pipeline and PipelineRun: c.Flags().BoolVarP(&opts.Follow, "follow", "f", false, "stream live logs") c.Flags().BoolVarP(&opts.Timestamps, "timestamps", "t", false, "show logs with timestamp") c.Flags().IntVarP(&opts.Limit, "limit", "", 5, "lists number of PipelineRuns") + c.Flags().BoolVarP(&opts.Prefixing, "prefix", "", true, "prefix each log line with the log source (task name and step name)") return c } From cfca172544bcab28db8c4a76495a09206a728d00 Mon Sep 17 00:00:00 2001 From: Abhishek Ghosh Date: Tue, 1 Apr 2025 15:13:24 +0530 Subject: [PATCH 2/4] updated the docs --- docs/cmd/tkn_pipeline_logs.md | 1 + docs/man/man1/tkn-pipeline-logs.1 | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/cmd/tkn_pipeline_logs.md b/docs/cmd/tkn_pipeline_logs.md index 6df6e856e1..7be16f2a5c 100644 --- a/docs/cmd/tkn_pipeline_logs.md +++ b/docs/cmd/tkn_pipeline_logs.md @@ -40,6 +40,7 @@ Show logs for given Pipeline and PipelineRun: -h, --help help for logs -L, --last show logs for last PipelineRun --limit int lists number of PipelineRuns (default 5) + --prefix prefix each log line with the log source (task name and step name) (default true) -t, --timestamps show logs with timestamp ``` diff --git a/docs/man/man1/tkn-pipeline-logs.1 b/docs/man/man1/tkn-pipeline-logs.1 index e8676ff797..df89e77ddd 100644 --- a/docs/man/man1/tkn-pipeline-logs.1 +++ b/docs/man/man1/tkn-pipeline-logs.1 @@ -39,6 +39,10 @@ Show Pipeline logs \fB\-\-limit\fP=5 lists number of PipelineRuns +.PP +\fB\-\-prefix\fP[=true] + prefix each log line with the log source (task name and step name) + .PP \fB\-t\fP, \fB\-\-timestamps\fP[=false] show logs with timestamp From bf7281a06a82d6fd31750d5ba699156307fd0361 Mon Sep 17 00:00:00 2001 From: Abhishek Ghosh Date: Tue, 15 Apr 2025 13:26:27 +0530 Subject: [PATCH 3/4] Add unit test scripts Signed-off-by: Abhishek Ghosh --- pkg/cmd/pipeline/logs_test.go | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/cmd/pipeline/logs_test.go b/pkg/cmd/pipeline/logs_test.go index c5b64df510..ebdcb7c1f6 100644 --- a/pkg/cmd/pipeline/logs_test.go +++ b/pkg/cmd/pipeline/logs_test.go @@ -265,6 +265,24 @@ func TestPipelineLog_v1beta1(t *testing.T) { wantError: false, want: "", }, + { + name: "Logs with prefix enabled (default)", + command: []string{"logs", pipelineName, "-n", ns, "-L"}, + namespace: ns, + dynamic: dc3, + input: cs3, + wantError: false, + want: "", + }, + { + name: "Logs with prefix disabled", + command: []string{"logs", pipelineName, "-n", ns, "--last", "--prefix=false"}, + namespace: ns, + dynamic: dc3, + input: cs3, + wantError: false, + want: "", + }, } for _, tp := range testParams { @@ -502,6 +520,24 @@ func TestPipelineLog(t *testing.T) { wantError: false, want: "", }, + { + name: "Logs with prefix enabled (default)", + command: []string{"logs", pipelineName, "-n", ns, "-L"}, + namespace: ns, + dynamic: dc3, + input: cs3, + wantError: false, + want: "", + }, + { + name: "Logs with prefix disabled", + command: []string{"logs", pipelineName, "-n", ns, "--last", "--prefix=false"}, + namespace: ns, + dynamic: dc3, + input: cs3, + wantError: false, + want: "", + }, } for _, tp := range testParams { From 65e88e9bcf1398377447fff9835e3938fe1da174 Mon Sep 17 00:00:00 2001 From: Abhishek Ghosh Date: Wed, 30 Apr 2025 11:46:24 +0530 Subject: [PATCH 4/4] Adjust pipeline logs test to align with updated output format Signed-off-by: Abhishek Ghosh --- test/e2e/pipeline/start_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/pipeline/start_test.go b/test/e2e/pipeline/start_test.go index f8ba360a52..b91b7fccec 100644 --- a/test/e2e/pipeline/start_test.go +++ b/test/e2e/pipeline/start_test.go @@ -78,7 +78,7 @@ func TestPipelineInteractiveStartE2E(t *testing.T) { }) t.Run("Validate pipeline logs, with follow mode (-f) and --last ", func(t *testing.T) { - res := tkn.Run(t, "pipeline", "logs", "--last", "-f") + res := tkn.Run(t, "pipeline", "logs", "--last", "-f", "--prefix=false") expected := "\n\ntest-e2e\n\n" helper.AssertOutput(t, expected, res.Stdout()) })