MCPcopy Index your code
hub / github.com/coder/coder / taskLogs

Method taskLogs

cli/task_logs.go:13–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func (r *RootCmd) taskLogs() *serpent.Command {
14 formatter := cliui.NewOutputFormatter(
15 cliui.TableFormat(
16 []codersdk.TaskLogEntry{},
17 []string{
18 "type",
19 "content",
20 },
21 ),
22 cliui.JSONFormat(),
23 )
24
25 cmd := &serpent.Command{
26 Use: "logs <task>",
27 Short: "Show a task's logs",
28 Long: FormatExamples(
29 Example{
30 Description: "Show logs for a given task.",
31 Command: "coder task logs task1",
32 }),
33 Middleware: serpent.Chain(
34 serpent.RequireNArgs(1),
35 ),
36 Handler: func(inv *serpent.Invocation) error {
37 client, err := r.InitClient(inv)
38 if err != nil {
39 return err
40 }
41
42 var (
43 ctx = inv.Context()
44 identifier = inv.Args[0]
45 )
46
47 task, err := client.TaskByIdentifier(ctx, identifier)
48 if err != nil {
49 return xerrors.Errorf("resolve task %q: %w", identifier, err)
50 }
51
52 logs, err := client.TaskLogs(ctx, codersdk.Me, task.ID)
53 if err != nil {
54 return xerrors.Errorf("get task logs: %w", err)
55 }
56
57 // Handle snapshot responses (paused/initializing/pending tasks).
58 if logs.Snapshot {
59 if logs.SnapshotAt == nil {
60 // No snapshot captured yet.
61 cliui.Warnf(inv.Stderr,
62 "Task is %s. No snapshot available (snapshot may have failed during pause, resume your task to view logs).\n",
63 task.Status)
64 }
65
66 // Snapshot exists with logs, show warning with count.
67 if len(logs.Logs) > 0 {
68 if len(logs.Logs) == 1 {
69 cliui.Warnf(inv.Stderr, "Task is %s. Showing last 1 message from snapshot.\n", task.Status)
70 } else {

Callers 1

tasksCommandMethod · 0.95

Calls 13

InitClientMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
WarnfFunction · 0.92
InfofFunction · 0.92
FormatExamplesFunction · 0.85
TaskByIdentifierMethod · 0.80
TaskLogsMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected