MCPcopy Create free account
hub / github.com/cli/cli / printLog

Function printLog

script/ghmock/log.go:102–149  ·  view source on GitHub ↗
(w io.Writer, entries []loggedRequest, full bool)

Source from the content-addressed store, hash-verified

100}
101
102func printLog(w io.Writer, entries []loggedRequest, full bool) {
103 var run, binary string
104 for _, e := range entries {
105 if e.Run != run || e.Binary != binary {
106 run, binary = e.Run, e.Binary
107 fmt.Fprintf(w, "=== run %s, gh %s\n", run, binary)
108 }
109 fmt.Fprintln(w, formatRequest(e))
110 if !full {
111 continue
112 }
113 if e.GraphQL != nil {
114 fmt.Fprintf(w, " %s %s\n", e.GraphQL.Kind, e.GraphQL.operationLabel())
115 if len(e.GraphQL.Variables) > 0 {
116 fmt.Fprintf(w, " variables: %s\n", compactJSON(e.GraphQL.Variables))
117 }
118 fmt.Fprintln(w, " query:")
119 for _, line := range splitLines(e.GraphQL.Query) {
120 fmt.Fprintf(w, " %s\n", line)
121 }
122 }
123 if e.Body != "" {
124 fmt.Fprintf(w, " body: %s\n", compactJSON([]byte(e.Body)))
125 }
126 if e.RawBody != nil {
127 fmt.Fprintf(w, " raw request body: %s (bytes in --json)\n", rawBodySummary(*e.RawBody))
128 }
129 if len(e.ResponseHeaders) > 0 {
130 names := slices.Sorted(maps.Keys(e.ResponseHeaders))
131 for i, name := range names {
132 names[i] = name + ": " + e.ResponseHeaders[name]
133 }
134 fmt.Fprintf(w, " response headers: %s\n", strings.Join(names, ", "))
135 }
136 if len(e.ResponseBody) > 0 {
137 fmt.Fprintf(w, " response: %s\n", compactJSON(e.ResponseBody))
138 }
139 if e.ResponseRawBody != nil {
140 fmt.Fprintf(w, " raw response body: %s (bytes in --json)\n", rawBodySummary(*e.ResponseRawBody))
141 }
142 for _, group := range problemGroups(e) {
143 fmt.Fprintf(w, " %s:\n", group.label)
144 for _, p := range group.problems {
145 fmt.Fprintf(w, " %s\n", p)
146 }
147 }
148 }
149}
150
151func rawBodySummary(body []byte) string {
152 return fmt.Sprintf("%d bytes, sha256 %x", len(body), sha256.Sum256(body))

Callers 1

cmdLogFunction · 0.85

Calls 7

formatRequestFunction · 0.85
splitLinesFunction · 0.85
rawBodySummaryFunction · 0.85
problemGroupsFunction · 0.85
operationLabelMethod · 0.80
JoinMethod · 0.80
compactJSONFunction · 0.70

Tested by

no test coverage detected