Skip to content

Remove duplicate logMiddleware.Printf calls in jqschema middleware#4809

Merged
lpcox merged 3 commits intomainfrom
copilot/duplicate-code-remove-dual-logging
Apr 29, 2026
Merged

Remove duplicate logMiddleware.Printf calls in jqschema middleware#4809
lpcox merged 3 commits intomainfrom
copilot/duplicate-code-remove-dual-logging

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

internal/middleware/jqschema.go logged every significant event twice — once via logMiddleware.Printf (debug logger, only active when DEBUG matches) and once via logger.Log* (always writes to the operational file). The two calls carried near-identical messages with minor drift in field ordering and naming.

Changes

  • Removed 14 redundant logMiddleware.Printf calls throughout WrapToolHandler and init() where a logger.Log* call already covered the same event. The logger.Log* calls are retained as the authoritative operational sink.
  • Preserved one standalone logMiddleware.Printf in applyJqSchema (default-timeout debug message) which has no logger.Log* counterpart.

Before

logMiddleware.Printf("Failed to save payload: tool=%s, queryID=%s, sessionID=%s, error=%v", toolName, queryID, sessionID, saveErr)
logger.LogError("payload", "Failed to save payload to filesystem: tool=%s, queryID=%s, session=%s, error=%v",
    toolName, queryID, sessionID, saveErr)

After

logger.LogError("payload", "Failed to save payload to filesystem: tool=%s, queryID=%s, session=%s, error=%v",
    toolName, queryID, sessionID, saveErr)

No log output is lost: logger.Log* calls always write to the file logger regardless of DEBUG, and logMiddleware.Printf (when enabled) would have only added a lightly-reformatted duplicate of the same message.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build3545495064/b513/launcher.test /tmp/go-build3545495064/b513/launcher.test -test.testlogfile=/tmp/go-build3545495064/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3545495064/b445/vet.cfg g_.a -I x_amd64/vet --gdwarf-5 race/v1 -o x_amd64/vet -W .cfg 9080194/b314/ x_amd64/vet . --gdwarf2 (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3545495064/b495/config.test /tmp/go-build3545495064/b495/config.test -test.testlogfile=/tmp/go-build3545495064/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3545495064/b436/vet.cfg uf@v1.36.11/types/known/wrapperspb/wrappers.pb.go ache/go/1.25.9/x64/src/net x_amd64/vet 9080194/b151/ ternal/engine/wa-atomic (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3545495064/b513/launcher.test /tmp/go-build3545495064/b513/launcher.test -test.testlogfile=/tmp/go-build3545495064/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3545495064/b445/vet.cfg g_.a -I x_amd64/vet --gdwarf-5 race/v1 -o x_amd64/vet -W .cfg 9080194/b314/ x_amd64/vet . --gdwarf2 (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3545495064/b513/launcher.test /tmp/go-build3545495064/b513/launcher.test -test.testlogfile=/tmp/go-build3545495064/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3545495064/b445/vet.cfg g_.a -I x_amd64/vet --gdwarf-5 race/v1 -o x_amd64/vet -W .cfg 9080194/b314/ x_amd64/vet . --gdwarf2 (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3545495064/b522/mcp.test /tmp/go-build3545495064/b522/mcp.test -test.testlogfile=/tmp/go-build3545495064/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s -qui�� .cfg E2Bv/XRonWiTfL4y-regex x_amd64/vet . -imultiarch x86_64-linux-gnu--format x_amd64/vet .cfg�� 9080194/b394/_pkg_.a ache/go/1.25.9/x64/src/vendor/golang.org/x/net/http/httpproxy/pr-nolocalimports x_amd64/vet --gdwarf-5 g/grpc/balancer/--version -o x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix duplicate logging in jqschema middleware Remove duplicate logMiddleware.Printf calls in jqschema middleware Apr 29, 2026
Copilot AI requested a review from lpcox April 29, 2026 16:42
@lpcox lpcox marked this pull request as ready for review April 29, 2026 16:43
Copilot AI review requested due to automatic review settings April 29, 2026 16:43
Copy link
Copy Markdown
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

Removes redundant debug-logger (logMiddleware.Printf) statements from the jq-schema middleware where equivalent logger.Log* operational logs already exist, reducing duplicate log volume and drift between message variants.

Changes:

  • Removed duplicate logMiddleware.Printf calls across init() and WrapToolHandler when the same event is already logged via logger.Log*.
  • Kept a single logMiddleware.Printf in applyJqSchema for the “default timeout applied” debug-only message.
Show a summary per file
File Description
internal/middleware/jqschema.go Removes duplicate debug logs while keeping operational logger.Log* logging as the primary sink.

Copilot's findings

Tip

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

Comments suppressed due to low confidence (1)

internal/middleware/jqschema.go:141

  • Same concern as the parse-error case: logger.LogError during package init may be a no-op until the file logger is initialized, so a compile failure could be effectively unlogged after removing the logMiddleware.Printf fallback. Consider using log.Printf/panic/os.Exit here (or another guaranteed startup-time sink) to ensure the failure is observable.
	)
	if jqSchemaCompileErr != nil {
		logger.LogError("startup", "Failed to compile jq schema filter at init (application will not start): %v", jqSchemaCompileErr)
		return
  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines 127 to 131
query, err := gojq.Parse(jqSchemaFilter)
if err != nil {
jqSchemaCompileErr = fmt.Errorf("failed to parse jq schema filter: %w", err)
logMiddleware.Printf("FATAL: Failed to parse jq schema filter at init: %v", err)
logger.LogError("startup", "Failed to parse jq schema filter at init (application will not start): %v", err)
return
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Apr 29, 2026

@copilot address the review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot address the review feedback

Done in 72f4a16. The two init() error branches (parse failure and compile failure) now use log.Printf (stdlib, always writes to stderr) instead of logger.LogError, so the error is always visible even before InitGatewayLoggers is called. The success-path logger.LogInfo is kept as-is since it fires only after a successful compile, at which point the operational log output being deferred until after logger initialization is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Dual Logging in jqschema Middleware

3 participants