Skip to content

Commit f2fd2c3

Browse files
feat: CP-1062 Remove excessive information returned from reading log files
1 parent 1fdbd19 commit f2fd2c3

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

internal/runners/mcp/downloadlogs/downloadlogs.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package downloadlogs
22

33
import (
4+
"bufio"
5+
"encoding/json"
46
"fmt"
57
"io"
68
"net/http"
@@ -29,20 +31,52 @@ func NewParams(logUrl string) *Params {
2931
}
3032
}
3133

34+
// Example: {"body": {"facility": "INFO", "msg": "..."}, "artifact_id": "...", "timestamp": "2025-08-12T19:23:51.702971", "type": "artifact_progress", "source": "build-wrapper", "pid": 19}
35+
type LogLine struct {
36+
Body struct {
37+
Msg string `json:"msg"`
38+
} `json:"body"`
39+
}
40+
3241
func (runner *DownloadLogsRunner) Run(params *Params) error {
3342
response, err := http.Get(params.logUrl)
3443
if err != nil {
3544
return fmt.Errorf("error while downloading logs: %v", err)
3645
}
3746
defer response.Body.Close()
3847

39-
body, err := io.ReadAll(response.Body)
40-
if err != nil {
41-
return fmt.Errorf("error reading response body: %v", err)
42-
}
4348
if response.StatusCode != 200 {
49+
body, _ := io.ReadAll(response.Body)
4450
return fmt.Errorf("error fetching logs: status %d, %s", response.StatusCode, body)
4551
}
46-
runner.output.Print(string(body))
52+
53+
scanner := bufio.NewScanner(response.Body)
54+
55+
startPrinting := false
56+
57+
for scanner.Scan() {
58+
var logLine LogLine
59+
line := scanner.Text()
60+
61+
if err := json.Unmarshal([]byte(line), &logLine); err != nil {
62+
continue // Skip malformed lines
63+
}
64+
65+
msg := logLine.Body.Msg
66+
67+
if !startPrinting {
68+
if msg == "Dependencies downloaded and unpacked." {
69+
startPrinting = true
70+
}
71+
continue
72+
}
73+
74+
runner.output.Print(msg + "\n")
75+
}
76+
77+
if err := scanner.Err(); err != nil {
78+
return fmt.Errorf("error reading log content: %v", err)
79+
}
80+
4781
return nil
4882
}

0 commit comments

Comments
 (0)