Skip to content

Commit 0f6216e

Browse files
authored
[log] Add debug logging to response_writer.go (#636)
## Changes Enhanced the `internal/server/response_writer.go` file with debug logging to improve troubleshooting capabilities for HTTP response handling. ### What was added: 1. **Logger declaration**: Added `logResponseWriter` with namespace `server:response_writer` following project conventions 2. **Response writer creation**: Logs when a new response writer is created 3. **Status code tracking**: Logs when HTTP status codes are set 4. **Body writes**: Logs the size of response body writes 5. **Data retrieval**: Logs when body content or status codes are retrieved ### Benefits: - Better visibility into HTTP response flow - Helps debug response-related issues - Follows the project's logger naming convention (`pkg:filename`) - No side effects in logger arguments - Minimal performance impact (logging only when DEBUG is enabled) ### Testing: The changes follow Go best practices and the project's logging guidelines from AGENTS.md. To see the debug output: ``````bash DEBUG=server:response_writer ./awmg --config config.toml `````` Or enable all server logs: ``````bash DEBUG=server:* ./awmg --config config.toml `````` ### Quality checklist: - ✅ Single file modified (focused PR) - ✅ No test files modified - ✅ Logger follows `pkg:filename` naming convention - ✅ Logger arguments have no side effects - ✅ Meaningful and helpful logging messages - ✅ No duplicate logging - ✅ Imports properly formatted > AI generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/21678050763) <!-- gh-aw-workflow-id: go-logger -->
2 parents daed5f1 + f1d54ef commit 0f6216e

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

internal/server/response_writer.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ package server
33
import (
44
"bytes"
55
"net/http"
6+
7+
"github.com/github/gh-aw-mcpg/internal/logger"
68
)
79

10+
var logResponseWriter = logger.New("server:response_writer")
11+
812
// responseWriter wraps http.ResponseWriter to capture response body and status code
913
// This unified implementation replaces loggingResponseWriter and sdkLoggingResponseWriter
1014
type responseWriter struct {
@@ -15,28 +19,34 @@ type responseWriter struct {
1519

1620
// newResponseWriter creates a new responseWriter with default status code
1721
func newResponseWriter(w http.ResponseWriter) *responseWriter {
22+
logResponseWriter.Print("Creating new response writer with default status 200")
1823
return &responseWriter{
1924
ResponseWriter: w,
2025
statusCode: http.StatusOK,
2126
}
2227
}
2328

2429
func (w *responseWriter) WriteHeader(statusCode int) {
30+
logResponseWriter.Printf("Setting response status code: %d", statusCode)
2531
w.statusCode = statusCode
2632
w.ResponseWriter.WriteHeader(statusCode)
2733
}
2834

2935
func (w *responseWriter) Write(b []byte) (int, error) {
36+
logResponseWriter.Printf("Writing response body: %d bytes", len(b))
3037
w.body.Write(b)
3138
return w.ResponseWriter.Write(b)
3239
}
3340

3441
// Body returns the captured response body as bytes
3542
func (w *responseWriter) Body() []byte {
36-
return w.body.Bytes()
43+
bodyBytes := w.body.Bytes()
44+
logResponseWriter.Printf("Retrieving captured body: %d bytes", len(bodyBytes))
45+
return bodyBytes
3746
}
3847

3948
// StatusCode returns the captured HTTP status code
4049
func (w *responseWriter) StatusCode() int {
50+
logResponseWriter.Printf("Retrieving captured status code: %d", w.statusCode)
4151
return w.statusCode
4252
}

0 commit comments

Comments
 (0)