Skip to content

Commit e7408e0

Browse files
chore(logs): add verbose logging for batch changes steps (#1242)
* batches/ui: add verbose logging to step execution Add detailed verbose logging to stepsExecTUI for batch changes execution. When -v flag is passed, users now see logs for: - Archive download start/completion/failure - Workspace initialization - Step caching (skipped steps) - Step preparation and execution - Step completion with diff size and file change counts - Step failures with exit codes * batches/ui: add verbose logging to pre-execution phases Add verbose logging to TUI for batch changes pre-execution steps: - Namespace resolution: show resolved namespace ID - Container images: log successful preparation - Workspace resolution: show workspace/repo counts and unsupported/ignored counts - Cache check: show cached specs and tasks to execute
1 parent 341290f commit e7408e0

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

internal/batches/ui/task_exec_tui.go

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func (ui *taskExecTUI) StepsExecutionUI(task *executor.Task) executor.StepsExecu
236236
}
237237

238238
return &stepsExecTUI{
239+
out: ui.out,
239240
task: task,
240241
updateStatusBar: func(message string) {
241242
ts.currentlyExecuting = message
@@ -427,50 +428,102 @@ func diffStatDiagram(stat diff.Stat) string {
427428
}
428429

429430
type stepsExecTUI struct {
431+
out *output.Output
430432
task *executor.Task
431433
updateStatusBar func(string)
432434
}
433435

434436
func (ui stepsExecTUI) ArchiveDownloadStarted() {
435437
ui.updateStatusBar("Downloading archive")
438+
ui.out.Verbosef("[%s] Downloading repository archive...", ui.task.Repository.Name)
436439
}
437-
func (ui stepsExecTUI) ArchiveDownloadFinished(err error) {}
440+
441+
func (ui stepsExecTUI) ArchiveDownloadFinished(err error) {
442+
if err != nil {
443+
ui.out.Verbosef("[%s] Archive download failed: %v", ui.task.Repository.Name, err)
444+
} else {
445+
ui.out.Verbosef("[%s] Archive download completed", ui.task.Repository.Name)
446+
}
447+
}
448+
438449
func (ui stepsExecTUI) WorkspaceInitializationStarted() {
439450
ui.updateStatusBar("Initializing workspace")
451+
ui.out.Verbosef("[%s] Initializing workspace...", ui.task.Repository.Name)
452+
}
453+
454+
func (ui stepsExecTUI) WorkspaceInitializationFinished() {
455+
ui.out.Verbosef("[%s] Workspace initialization completed", ui.task.Repository.Name)
440456
}
441-
func (ui stepsExecTUI) WorkspaceInitializationFinished() {}
457+
442458
func (ui stepsExecTUI) SkippingStepsUpto(startStep int) {
443459
switch startStep {
444460
case 1:
445461
ui.updateStatusBar("Skipping step 1. Found cached result.")
462+
ui.out.Verbosef("[%s] Skipping step 1 (cached result found)", ui.task.Repository.Name)
446463
default:
447464
ui.updateStatusBar(fmt.Sprintf("Skipping steps 1 to %d. Found cached results.", startStep))
465+
ui.out.Verbosef("[%s] Skipping steps 1 to %d (cached results found)", ui.task.Repository.Name, startStep)
448466
}
449467
}
450468

451469
func (ui stepsExecTUI) StepSkipped(step int) {
452470
ui.updateStatusBar(fmt.Sprintf("Skipping step %d", step))
471+
ui.out.Verbosef("[%s] Step %d skipped", ui.task.Repository.Name, step)
453472
}
473+
454474
func (ui stepsExecTUI) StepPreparingStart(step int) {
455475
ui.updateStatusBar(fmt.Sprintf("Preparing step %d", step))
476+
ui.out.Verbosef("[%s] Preparing step %d...", ui.task.Repository.Name, step)
456477
}
478+
457479
func (ui stepsExecTUI) StepPreparingSuccess(step int) {
458-
// noop right now
480+
ui.out.Verbosef("[%s] Step %d preparation completed", ui.task.Repository.Name, step)
459481
}
482+
460483
func (ui stepsExecTUI) StepPreparingFailed(step int, err error) {
461-
// noop right now
484+
ui.out.Verbosef("[%s] Step %d preparation failed: %v", ui.task.Repository.Name, step, err)
462485
}
463-
func (ui stepsExecTUI) StepStarted(step int, runScript string, _ map[string]string) {
486+
487+
func (ui stepsExecTUI) StepStarted(step int, runScript string, env map[string]string) {
464488
ui.updateStatusBar(runScript)
489+
ui.out.Verbosef("[%s] Step %d started: %s", ui.task.Repository.Name, step, truncateScript(runScript, 100))
490+
if len(env) > 0 {
491+
ui.out.Verbosef("[%s] Step %d environment variables: %d set", ui.task.Repository.Name, step, len(env))
492+
}
465493
}
466494

467495
func (ui stepsExecTUI) StepOutputWriter(ctx context.Context, task *executor.Task, step int) executor.StepOutputWriter {
468496
return executor.NoopStepOutputWriter{}
469497
}
470498

471499
func (ui stepsExecTUI) StepFinished(idx int, diff []byte, changes git.Changes, outputs map[string]any) {
472-
// noop right now
500+
ui.out.Verbosef("[%s] Step %d finished successfully", ui.task.Repository.Name, idx)
501+
if len(diff) > 0 {
502+
ui.out.Verbosef("[%s] Step %d produced %d bytes of diff", ui.task.Repository.Name, idx, len(diff))
503+
}
504+
if len(changes.Modified)+len(changes.Added)+len(changes.Deleted)+len(changes.Renamed) > 0 {
505+
ui.out.Verbosef("[%s] Step %d changes: %d modified, %d added, %d deleted, %d renamed",
506+
ui.task.Repository.Name, idx,
507+
len(changes.Modified), len(changes.Added), len(changes.Deleted), len(changes.Renamed))
508+
}
509+
if len(outputs) > 0 {
510+
ui.out.Verbosef("[%s] Step %d outputs: %d variables set", ui.task.Repository.Name, idx, len(outputs))
511+
}
473512
}
513+
474514
func (ui stepsExecTUI) StepFailed(idx int, err error, exitCode int) {
475-
// noop right now
515+
ui.out.Verbosef("[%s] Step %d failed (exit code %d): %v", ui.task.Repository.Name, idx, exitCode, err)
516+
}
517+
518+
// truncateScript truncates a script string for display purposes
519+
func truncateScript(script string, maxLen int) string {
520+
lines := strings.Split(script, "\n")
521+
firstLine := lines[0]
522+
if len(firstLine) > maxLen {
523+
return firstLine[:maxLen] + "..."
524+
}
525+
if len(lines) > 1 {
526+
return firstLine + " ..."
527+
}
528+
return firstLine
476529
}

internal/batches/ui/tui.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ func (ui *TUI) ResolvingNamespace() {
6363
ui.pending = batchCreatePending(ui.Out, "Resolving namespace")
6464
}
6565

66-
func (ui *TUI) ResolvingNamespaceSuccess(_namespace string) {
66+
func (ui *TUI) ResolvingNamespaceSuccess(namespace string) {
6767
batchCompletePending(ui.pending, "Resolving namespace")
68+
ui.Out.Verbosef("Resolved namespace: %s", namespace)
6869
}
6970

7071
func (ui *TUI) PreparingContainerImages() {
@@ -80,6 +81,7 @@ func (ui *TUI) PreparingContainerImagesProgress(done, total int) {
8081

8182
func (ui *TUI) PreparingContainerImagesSuccess() {
8283
ui.progress.Complete()
84+
ui.Out.Verbosef("Container images prepared successfully")
8385
}
8486

8587
func (ui *TUI) DeterminingWorkspaceCreatorType() {
@@ -104,13 +106,16 @@ func (ui *TUI) DeterminingWorkspaces() {
104106
func (ui *TUI) DeterminingWorkspacesSuccess(workspacesCount, reposCount int, unsupported batches.UnsupportedRepoSet, ignored batches.IgnoredRepoSet) {
105107
batchCompletePending(ui.pending, fmt.Sprintf("Resolved %d workspaces from %d repositories", workspacesCount, reposCount))
106108

109+
ui.Out.Verbosef("Workspace resolution: %d workspaces across %d repositories", workspacesCount, reposCount)
107110
if len(unsupported) != 0 {
111+
ui.Out.Verbosef("Unsupported repositories: %d", len(unsupported))
108112
block := ui.Out.Block(output.Line(" ", output.StyleWarning, "Some repositories are hosted on unsupported code hosts and will be skipped. Use the -allow-unsupported flag to avoid skipping them."))
109113
for repo := range unsupported {
110114
block.Write(repo.Name)
111115
}
112116
block.Close()
113117
} else if len(ignored) != 0 {
118+
ui.Out.Verbosef("Ignored repositories (have .batchignore): %d", len(ignored))
114119
block := ui.Out.Block(output.Line(" ", output.StyleWarning, "The repositories listed below contain .batchignore files and will be skipped. Use the -force-override-ignore flag to avoid skipping them."))
115120
for repo := range ignored {
116121
block.Write(repo.Name)
@@ -163,6 +168,7 @@ func (ui *TUI) CheckingCacheSuccess(cachedSpecsFound int, uncachedTasks int) {
163168
default:
164169
batchCompletePending(ui.pending, fmt.Sprintf("%s; %d tasks need to be executed", specsFoundMessage, uncachedTasks))
165170
}
171+
ui.Out.Verbosef("Cache check: %d cached specs found, %d tasks to execute", cachedSpecsFound, uncachedTasks)
166172
}
167173

168174
func (ui *TUI) ExecutingTasks(verbose bool, parallelism int) executor.TaskExecutionUI {

0 commit comments

Comments
 (0)