Skip to content

Commit de8e888

Browse files
committed
Add long flag --display-name to display the log of pipelinerun
1 parent dd06e6b commit de8e888

File tree

10 files changed

+38
-11
lines changed

10 files changed

+38
-11
lines changed

docs/cmd/tkn_pipelinerun_logs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Show the logs of PipelineRun named 'microservice-1' for all Tasks and steps (inc
3131

3232
```
3333
-a, --all show all logs including init steps injected by tekton
34+
--display-name show logs with task display name (display name and step name)
3435
-E, --exit-with-pipelinerun-error exit with pipelinerun to the unix shell, 0 if success, 1 if error, 2 on unknown status
3536
-f, --follow stream live logs
3637
-F, --fzf use fzf to select a PipelineRun

docs/man/man1/tkn-pipelinerun-logs.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Show the logs of a PipelineRun
2323
\fB\-a\fP, \fB\-\-all\fP[=false]
2424
show all logs including init steps injected by tekton
2525

26+
.PP
27+
\fB\-\-display\-name\fP[=false]
28+
show logs with task display name (display name and step name)
29+
2630
.PP
2731
\fB\-E\fP, \fB\-\-exit\-with\-pipelinerun\-error\fP[=false]
2832
exit with pipelinerun to the unix shell, 0 if success, 1 if error, 2 on unknown status

pkg/cmd/pipelinerun/logs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Show the logs of PipelineRun named 'microservice-1' for all Tasks and steps (inc
8484
c.Flags().BoolVarP(&opts.Follow, "follow", "f", false, "stream live logs")
8585
c.Flags().BoolVarP(&opts.Timestamps, "timestamps", "", false, "show logs with timestamp")
8686
c.Flags().BoolVarP(&opts.Prefixing, "prefix", "", true, "prefix each log line with the log source (task name and step name)")
87+
c.Flags().BoolVarP(&opts.DisplayName, "display-name", "", false, "show logs with task display name (display name and step name)")
8788
c.Flags().BoolVarP(&opts.ExitWithPrError, "exit-with-pipelinerun-error", "E", false, "exit with pipelinerun to the unix shell, 0 if success, 1 if error, 2 on unknown status")
8889
c.Flags().StringSliceVarP(&opts.Tasks, "task", "t", []string{}, "show logs for mentioned Tasks only")
8990
c.Flags().IntVarP(&opts.Limit, "limit", "", defaultLimit, "lists number of PipelineRuns")
@@ -110,7 +111,7 @@ func Run(opts *options.LogOptions) error {
110111
return err
111112
}
112113

113-
log.NewWriter(log.LogTypePipeline, opts.Prefixing).Write(opts.Stream, logC, errC)
114+
log.NewWriter(log.LogTypePipeline, opts.Prefixing).WithDisplayName(opts.DisplayName).Write(opts.Stream, logC, errC)
114115

115116
// get pipelinerun status
116117
if opts.ExitWithPrError {

pkg/log/log.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ var pipelineGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Res
2727

2828
// Log represents data to write on log channel
2929
type Log struct {
30-
Pipeline string
31-
Task string
32-
Step string
33-
Log string
30+
Pipeline string
31+
Task string
32+
TaskDisplayName string
33+
Step string
34+
Log string
3435
}

pkg/log/pipeline_reader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (r *Reader) pipeLogs(logC chan<- Log, errC chan<- error) {
192192
tlogC = nil
193193
continue
194194
}
195-
logC <- Log{Task: l.Task, Step: l.Step, Log: l.Log}
195+
logC <- Log{Task: l.Task, TaskDisplayName: l.TaskDisplayName, Step: l.Step, Log: l.Log}
196196

197197
case e, ok := <-terrC:
198198
if !ok {
@@ -208,6 +208,7 @@ func (r *Reader) setUpTask(taskNumber int, tr taskrunpkg.Run) {
208208
r.setNumber(taskNumber)
209209
r.setRun(tr.Name)
210210
r.setTask(tr.Task)
211+
r.setDisplayName(tr.DisplayName)
211212
r.setRetries(tr.Retries)
212213
}
213214

pkg/log/reader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Reader struct {
3737
steps []string
3838
logType string
3939
task string
40+
displayName string
4041
number int
4142
activityTimeout time.Duration
4243
retries int
@@ -108,6 +109,10 @@ func (r *Reader) setTask(task string) {
108109
r.task = task
109110
}
110111

112+
func (r *Reader) setDisplayName(displayName string) {
113+
r.displayName = displayName
114+
}
115+
111116
func (r *Reader) clone() *Reader {
112117
c := *r
113118
return &c

pkg/log/task_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ func (r *Reader) readStepsLogs(logC chan<- Log, errC chan<- error, steps []*step
138138
case l, ok := <-containerLogC:
139139
if !ok {
140140
containerLogC = nil
141-
logC <- Log{Task: r.task, Step: step.name, Log: "EOFLOG"}
141+
logC <- Log{Task: r.task, TaskDisplayName: r.displayName, Step: step.name, Log: "EOFLOG"}
142142
continue
143143
}
144-
logC <- Log{Task: r.task, Step: step.name, Log: l.Log}
144+
logC <- Log{Task: r.task, TaskDisplayName: r.displayName, Step: step.name, Log: l.Log}
145145

146146
case e, ok := <-containerLogErrC:
147147
if !ok {

pkg/log/writer.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import (
2323

2424
// Writer helps logging pod"s log
2525
type Writer struct {
26-
fmt *formatted.Color
27-
logType string
28-
prefixing bool
26+
fmt *formatted.Color
27+
logType string
28+
prefixing bool
29+
displayName bool
2930
}
3031

3132
// NewWriter returns the new instance of LogWriter
@@ -37,6 +38,12 @@ func NewWriter(logType string, prefixing bool) *Writer {
3738
}
3839
}
3940

41+
// WithDisplayName sets the display name
42+
func (lw *Writer) WithDisplayName(displayName bool) *Writer {
43+
lw.displayName = displayName
44+
return lw
45+
}
46+
4047
// Write formatted pod's logs
4148
func (lw *Writer) Write(s *cli.Stream, logC <-chan Log, errC <-chan error) {
4249
for logC != nil || errC != nil {
@@ -52,6 +59,10 @@ func (lw *Writer) Write(s *cli.Stream, logC <-chan Log, errC <-chan error) {
5259
continue
5360
}
5461

62+
if lw.displayName && l.TaskDisplayName != "" {
63+
l.Task = l.TaskDisplayName
64+
}
65+
5566
if lw.prefixing {
5667
switch lw.logType {
5768
case LogTypePipeline:

pkg/options/logs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type LogOptions struct {
5151
Tail int64
5252
Timestamps bool
5353
Prefixing bool
54+
DisplayName bool
5455
ExitWithPrError bool
5556
// ActivityTimeout is the amount of time to wait for some activity
5657
// (e.g. Pod ready) before giving up.

pkg/taskrun/taskrun.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
type Run struct {
2525
Name string
26+
DisplayName string
2627
Task string
2728
Retries int
2829
StartTime *metav1.Time
@@ -92,6 +93,7 @@ func SortTasksBySpecOrder(pipelineTasks []v1.PipelineTask, pipelinesTaskRuns map
9293
trs = append(trs, Run{
9394
Task: ts.Name,
9495
Name: n,
96+
DisplayName: ts.DisplayName,
9597
Retries: ts.Retries,
9698
StartTime: trStatusFields.StartTime,
9799
CompletionTime: trStatusFields.CompletionTime,

0 commit comments

Comments
 (0)