Commit 37654a5
authored
[log] Add debug logging to writeGatewayConfig in cmd/root.go (#1545)
## Summary
Adds 5 debug logging calls to the `writeGatewayConfig` function in
`internal/cmd/root.go`, which previously had zero debug visibility.
## Why This Function?
`writeGatewayConfig` produces the JSON configuration that downstream
clients use to connect to the gateway (written to stdout per [MCP
Gateway Specification Section
5.4](https://github.com/github/gh-aw/blob/main/docs/src/content/docs/reference/mcp-gateway.md)).
When clients have trouble connecting, this function is a key diagnostic
point, but it had no debug logging at all.
## Changes
Added 5 `debugLog.Printf` calls to `writeGatewayConfig`:
| Location | What is logged |
|---|---|
| Function entry | `listenAddr`, `mode`, server count |
| After `net.SplitHostPort` | Resolved `host` and `port` |
| After API key extraction | Whether an API key is configured (boolean
only — key value is **never** logged) |
| Inside the per-server loop | Server `name`, its output `url`, and
`toolCount` |
| After JSON encoding | Total server count written |
## Logging Design
- **Reuses existing logger**: `debugLog = logger.New("cmd:root")`
already declared in this file — no new logger added
- **No side effects**: All format arguments are pre-computed values
(`len()`, `apiKey != ""`, etc.) — no function calls
- **Zero overhead when not debugging**: Logs are gated by the `DEBUG`
environment variable (e.g., `DEBUG=cmd:*`)
- **Security-safe**: The API key value is never logged; only whether one
is configured (`apiKeyConfigured=true/false`)
## Example Debug Output
```
cmd:root Writing gateway config: listenAddr=127.0.0.1:3000, mode=routed, servers=2
cmd:root Resolved gateway address: host=127.0.0.1, port=3000
cmd:root Gateway auth: apiKeyConfigured=true
cmd:root Wrote server config entry: name=github, url=(127.0.0.1/redacted) toolCount=0
cmd:root Wrote server config entry: name=slack, url=(127.0.0.1/redacted) toolCount=3
cmd:root Gateway config written successfully: serverCount=2
```
## Quality Checklist
- [x] Exactly 1 file modified
- [x] No test files modified
- [x] Logger reused (not added) — `debugLog` already existed
- [x] Logger naming follows `pkg:filename` convention (`cmd:root`)
- [x] Logger arguments don't compute anything or cause side effects
- [x] Messages are meaningful and help debug connection issues
- [x] No duplicate logging with existing `log.Printf` messages (those
are for users; these are for developers)
> Generated by [Go Logger
Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/22583491106)
<!-- gh-aw-agentic-workflow: Go Logger Enhancement, engine: copilot, id:
22583491106, workflow_id: go-logger, run:
https://github.com/github/gh-aw-mcpg/actions/runs/22583491106 -->
<!-- gh-aw-workflow-id: go-logger -->3 files changed
Lines changed: 20 additions & 99 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
| 362 | + | |
| 363 | + | |
362 | 364 | | |
363 | 365 | | |
364 | 366 | | |
365 | 367 | | |
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
| 371 | + | |
| 372 | + | |
369 | 373 | | |
370 | 374 | | |
371 | 375 | | |
| |||
402 | 406 | | |
403 | 407 | | |
404 | 408 | | |
| 409 | + | |
| 410 | + | |
405 | 411 | | |
406 | 412 | | |
407 | 413 | | |
| |||
413 | 419 | | |
414 | 420 | | |
415 | 421 | | |
| 422 | + | |
| 423 | + | |
416 | 424 | | |
417 | 425 | | |
418 | 426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | 140 | | |
228 | 141 | | |
229 | 142 | | |
| |||
0 commit comments