Skip to content

[log] Add debug logging to response_writer.go#636

Merged
lpcox merged 1 commit intomainfrom
add-logging-response-writer-875c097498b4e57c
Feb 5, 2026
Merged

[log] Add debug logging to response_writer.go#636
lpcox merged 1 commit intomainfrom
add-logging-response-writer-875c097498b4e57c

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Feb 4, 2026

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:

DEBUG=server:response_writer ./awmg --config config.toml

Or enable all server logs:

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

- Added logger declaration with namespace server:response_writer

- Added logging for response writer creation

- Added logging for status code changes and body writes
@github-actions github-actions bot added automation enhancement New feature or request labels Feb 4, 2026
@lpcox lpcox marked this pull request as ready for review February 5, 2026 05:16
Copilot AI review requested due to automatic review settings February 5, 2026 05:16
@lpcox lpcox merged commit 0f6216e into main Feb 5, 2026
3 checks passed
@lpcox lpcox deleted the add-logging-response-writer-875c097498b4e57c branch February 5, 2026 05:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds debug logging to the response_writer.go file to improve troubleshooting capabilities for HTTP response handling. The changes introduce a logger with the namespace server:response_writer and add logging statements to track response writer creation, status code setting, body writes, and data retrieval operations.

Changes:

  • Added logger initialization following the project's pkg:filename naming convention
  • Added debug logging to newResponseWriter, WriteHeader, Write, Body, and StatusCode methods
  • Modified Body() method to store body bytes in intermediate variable for logging
Comments suppressed due to low confidence (3)

internal/server/response_writer.go:22

  • The newResponseWriter() function is called for every HTTP request (as seen in sdk_logging.go line 79 and transport.go line 49). This logging adds function call overhead on every single request. While minimal, this is on the critical path for all HTTP requests. The information logged here has limited debugging value since it's a constant message that doesn't include any request-specific context. Consider removing this logging to minimize overhead on the hot path.
	logResponseWriter.Print("Creating new response writer with default status 200")

internal/server/response_writer.go:45

  • The Body() method adds logging that requires storing the body bytes in an intermediate variable just for logging purposes. This is unnecessary overhead. The logging adds minimal value since the body bytes are already logged at a higher level by callers (e.g., in sdk_logging.go and transport.go). Additionally, this method may be called multiple times per request (as seen in transport.go line 51-52 where both lw.Body() and string(lw.Body()) are called), resulting in duplicate log messages for the same data. Consider removing this logging statement.
	bodyBytes := w.body.Bytes()
	logResponseWriter.Printf("Retrieving captured body: %d bytes", len(bodyBytes))
	return bodyBytes

internal/server/response_writer.go:51

  • The StatusCode() method is called multiple times per request (e.g., in sdk_logging.go it's called 4 times - lines 95, 136, 147, 156). Each call will generate a separate log message, creating noise without providing additional useful information. The status code value is already logged at a higher level by callers. Consider removing this logging statement to reduce log verbosity.
	logResponseWriter.Printf("Retrieving captured status code: %d", w.statusCode)
	return w.statusCode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

func (w *responseWriter) Write(b []byte) (int, error) {
logResponseWriter.Printf("Writing response body: %d bytes", len(b))
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Write() method is called on every response body write operation, which can happen multiple times per request. For large responses written in chunks, this will generate excessive log messages. This is a hot path in HTTP request handling. While the logger only outputs when DEBUG is enabled, the function call overhead and string formatting still occur. Consider using log.Enabled() check before logging, or remove this logging entirely since response bodies are already logged at a higher level by the callers (e.g., sdk_logging.go and transport.go).

This issue also appears in the following locations of the same file:

  • line 22
  • line 43
  • line 50

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants