Skip to content

feat: support agent friendly logs - #3440

Open
Debashich wants to merge 2 commits into
tektoncd:mainfrom
Debashich:feat/agent-friendly-logs
Open

Debashich wants to merge 2 commits into
tektoncd:mainfrom
Debashich:feat/agent-friendly-logs

Conversation

@Debashich

@Debashich Debashich commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Add JSON output support to tkn pipelinerun logs and tkn taskrun logs, making log output easier for agents and automated tools to consume.

  • Add -o/--output flag to both commands.
  • Support newline-delimited JSON (NDJSON), emitting one JSON object per log entry.
  • Include task, step, timestamp, and message fields in log records.
  • Preserve Kubernetes-provided log timestamps.
  • Support streaming JSON output with --follow.
  • Keep existing human-readable output as the default.
  • Update command documentation and man pages.

Closes #2854

Submitter Checklist

See [the contribution guide](https://github.com/tektoncd/cli/blob/master/CONTRIBUTING.md) for more details.

Release Notes

Add JSON output support to PipelineRun and TaskRun logs commands.

Signed-off-by: Debashich <debashishsinha555@gmail.com>
Signed-off-by: Debashich <debashishsinha555@gmail.com>
@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Nov 17, 2026
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign pratap0007 after the PR has been reviewed.
You can assign the PR to them by writing /assign @pratap0007 in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 17, 2026
@Debashich Debashich changed the title Feat/agent friendly logs feat: support agent friendly logs Nov 17, 2026
@Debashich

Copy link
Copy Markdown
Contributor Author

Hey @divyansh42! Got this ready for review. Whenever you get some time PTAL

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved issues drop requested timestamps from text logs, contaminate JSON output with plain-text diagnostics, and can cause a panic on null termination-message entries.

3 open issues
What changed in this PR

Adds structured log output to tkn pipelinerun logs and tkn taskrun logs for agents and automated tools, using the shared log-reading and formatting infrastructure.

Changes:

  • Adds -o/--output json for newline-delimited JSON, including follow mode.
  • Carries Kubernetes timestamps into structured records with task, step, and message fields.
  • Updates command references and man pages; human-readable output remains the default.
File Description
pkg/​pods/​container.go Extracts timestamps from Kubernetes log lines.
pkg/​options/​logs.go Adds the output-format option.
pkg/​log/​writer.go Encodes structured log records as NDJSON.
pkg/​log/​task_reader.go Forwards timestamps and changes termination-result decoding.
pkg/​log/​pipeline_reader.go Forwards timestamps through pipeline logs.
pkg/​log/​log.go Adds timestamps to shared log records.
pkg/​cmd/​taskrun/​logs.go Exposes and configures JSON output for TaskRun logs.
pkg/​cmd/​pipelinerun/​logs.go Exposes and configures JSON output for PipelineRun logs.
docs/​man/​man1/​tkn-taskrun-logs.1 Documents the TaskRun output flag.
docs/​man/​man1/​tkn-pipelinerun-logs.1 Documents the PipelineRun output flag.
docs/​cmd/​tkn_taskrun_logs.md Updates the TaskRun command reference.
docs/​cmd/​tkn_pipelinerun_logs.md Updates the PipelineRun command reference.

Review effort: Balanced

Comment on lines +110 to 115
if opts.Output == "json" {
opts.Timestamps = true
opts.Prefixing = false
}

lr, err := log.NewReader(log.LogTypePipeline, opts)
Comment thread pkg/log/task_reader.go
// a real failure is a "Skipped" reason in the termination message.
func isSkippedStep(term *corev1.ContainerStateTerminated) bool {
var results []result.RunResult
var results []*result.RunResult
Comment thread pkg/log/writer.go
lw.fmt.Rainbow.Fprintf(l.Step, s.Out, "[%s] ", l.Step)
}
}
fmt.Fprintf(s.Out, "%s\n", l.Log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make pipelinerun/taskrun logs agent-friendly

3 participants