Refactor: Extract triple-logging helpers to eliminate duplicate logging patterns#945
Draft
Refactor: Extract triple-logging helpers to eliminate duplicate logging patterns#945
Conversation
…ng patterns - Add inline helper functions (tripleLogInfo, tripleLogWarn, tripleLogError) - Reduces code duplication by 25% (44 to 33 logging calls) - Refactor logSecurityWarning, logLaunchStart, logLaunchError, logTimeoutError, logLaunchSuccess - All helpers are inline in log_helpers.go following marshalToResponse pattern - Maintains identical logging behavior while improving maintainability Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
internal/launcher/log_helpers.gofile contained a repetitive triple-logging pattern where every logging operation called three different loggers in sequence: file logger (logger.LogInfoWithServer), stdout (log.Printf), and debug logger (logLauncher.Printf). This pattern appeared 6+ times across different functions.Changes
Added inline helper functions (following the
marshalToResponsepattern frominternal/mcp/connection.go):tripleLogInfo()- encapsulates info-level logging to all three destinationstripleLogWarn()- encapsulates warning-level logging with variadic stdout messagestripleLogError()- encapsulates error-level logging with optional debug messageRefactored 5 logging functions to use helpers:
logSecurityWarninglogLaunchStartlogLaunchErrorlogTimeoutErrorlogLaunchSuccessImpact
Example
Before:
After:
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/tmp/go-build2698919314/b001/launcher.test /tmp/go-build2698919314/b001/launcher.test -test.testlogfile=/tmp/go-build2698919314/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.run=^Test 64/src/net/cgo_u--abbrev-ref 64/src/net/cgo_uHEAD /usr/local/bin/git ache/go/1.25.7/xbase64 -trimpath 64/pkg/tool/linux_amd64/vet ; \#system# !d; HEAD rev-�� --abbrev-ref HEAD k/_temp/ghcca-node/node/bin/git /opt/hostedtoolcbase64 .cfg if (a[i] < b[i]) exit(3); else if (a[i] > b[i]) exit(0) base64(dns block)/tmp/go-build3935831774/b001/launcher.test /tmp/go-build3935831774/b001/launcher.test -test.testlogfile=/tmp/go-build3935831774/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -d -fmessage-length--abbrev-ref 64/pkg/tool/linuHEAD x_amd64/compile 0, length(NVM_DIdocker 5565171/b165/ cal/bin/as x_amd64/compile rev-�� --abbrev-ref HEAD cal/bin/git ache/go/1.25.7/xbase64 -I .cfg base64(dns block)/tmp/go-build846594381/b279/launcher.test /tmp/go-build846594381/b279/launcher.test -test.testlogfile=/tmp/go-build846594381/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true \t /opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/compile k/_temp/ghcca-node/node/bin/git ead x_amd64/compile /usr/bin/base64 base64 -d 64/pkg/tool/linu--abbrev-ref base64 64/pkg/tool/linux_amd64/vet -lang=go1.25 64/pkg/tool/linu-d /usr/sbin/git 64/pkg/tool/linux_amd64/vet(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build4175565171/b260/config.test /tmp/go-build4175565171/b260/config.test -test.testlogfile=/tmp/go-build4175565171/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go /v2/chacha8.go 64/pkg/tool/linu.c(dns block)nonexistent.local/tmp/go-build2698919314/b001/launcher.test /tmp/go-build2698919314/b001/launcher.test -test.testlogfile=/tmp/go-build2698919314/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.run=^Test 64/src/net/cgo_u--abbrev-ref 64/src/net/cgo_uHEAD /usr/local/bin/git ache/go/1.25.7/xbase64 -trimpath 64/pkg/tool/linux_amd64/vet ; \#system# !d; HEAD rev-�� --abbrev-ref HEAD k/_temp/ghcca-node/node/bin/git /opt/hostedtoolcbase64 .cfg if (a[i] < b[i]) exit(3); else if (a[i] > b[i]) exit(0) base64(dns block)/tmp/go-build3935831774/b001/launcher.test /tmp/go-build3935831774/b001/launcher.test -test.testlogfile=/tmp/go-build3935831774/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -d -fmessage-length--abbrev-ref 64/pkg/tool/linuHEAD x_amd64/compile 0, length(NVM_DIdocker 5565171/b165/ cal/bin/as x_amd64/compile rev-�� --abbrev-ref HEAD cal/bin/git ache/go/1.25.7/xbase64 -I .cfg base64(dns block)/tmp/go-build846594381/b279/launcher.test /tmp/go-build846594381/b279/launcher.test -test.testlogfile=/tmp/go-build846594381/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true \t /opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/compile k/_temp/ghcca-node/node/bin/git ead x_amd64/compile /usr/bin/base64 base64 -d 64/pkg/tool/linu--abbrev-ref base64 64/pkg/tool/linux_amd64/vet -lang=go1.25 64/pkg/tool/linu-d /usr/sbin/git 64/pkg/tool/linux_amd64/vet(dns block)slow.example.com/tmp/go-build2698919314/b001/launcher.test /tmp/go-build2698919314/b001/launcher.test -test.testlogfile=/tmp/go-build2698919314/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.run=^Test 64/src/net/cgo_u--abbrev-ref 64/src/net/cgo_uHEAD /usr/local/bin/git ache/go/1.25.7/xbase64 -trimpath 64/pkg/tool/linux_amd64/vet ; \#system# !d; HEAD rev-�� --abbrev-ref HEAD k/_temp/ghcca-node/node/bin/git /opt/hostedtoolcbase64 .cfg if (a[i] < b[i]) exit(3); else if (a[i] > b[i]) exit(0) base64(dns block)/tmp/go-build3935831774/b001/launcher.test /tmp/go-build3935831774/b001/launcher.test -test.testlogfile=/tmp/go-build3935831774/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -d -fmessage-length--abbrev-ref 64/pkg/tool/linuHEAD x_amd64/compile 0, length(NVM_DIdocker 5565171/b165/ cal/bin/as x_amd64/compile rev-�� --abbrev-ref HEAD cal/bin/git ache/go/1.25.7/xbase64 -I .cfg base64(dns block)/tmp/go-build846594381/b279/launcher.test /tmp/go-build846594381/b279/launcher.test -test.testlogfile=/tmp/go-build846594381/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true \t /opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/compile k/_temp/ghcca-node/node/bin/git ead x_amd64/compile /usr/bin/base64 base64 -d 64/pkg/tool/linu--abbrev-ref base64 64/pkg/tool/linux_amd64/vet -lang=go1.25 64/pkg/tool/linu-d /usr/sbin/git 64/pkg/tool/linux_amd64/vet(dns block)this-host-does-not-exist-12345.com/tmp/go-build4175565171/b284/mcp.test /tmp/go-build4175565171/b284/mcp.test -test.testlogfile=/tmp/go-build4175565171/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go gKxUsK41W /usr/sbin/git ; s#/opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/vet --global nfig/composer/ve-bool 64/pkg/include ortc�� go 64/src/internal/-ifaceassert 64/pkg/tool/linu-nilfunc -b lpers.go /home/REDACTED/.lo--version 64/pkg/tool/linu-tests(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[duplicate-code] Multi-Level Logging Calls Duplication</issue_title>
<issue_description># 🔍 Duplicate Code Pattern: Multi-Level Logging Calls
Part of duplicate code analysis: #929
Summary
The
internal/launcher/log_helpers.gofile exhibits a repetitive triple-logging pattern where every logging operation calls three different loggers in sequence:logger.LogInfoWithServer()(file logger),log.Printf()(stdout), andlogLauncher.Printf()(debug logger). This pattern appears 6+ times across different functions.Duplication Details
Pattern: Triple Logging Calls
Severity: Medium
Occurrences: 6+ instances across 6 functions
Locations:
internal/launcher/log_helpers.golines 23-27 (logSecurityWarning)internal/launcher/log_helpers.golines 33-35, 37-40 (logLaunchStart- 2x)internal/launcher/log_helpers.golines 69-75 (logLaunchError)internal/launcher/log_helpers.golines 96-105 (logTimeoutError- 2x)internal/launcher/log_helpers.golines 111-117 (logLaunchSuccess- 2x)Code Sample:
Another Example:
Impact Analysis
Refactoring Recommendations
Option 1: Unified Launcher Logger Wrapper (Recommended)
internal/launcher/launcher_logger.goOption 2: Structured Logging Event System
Option 3: Logging Middleware/Interceptor
Implementation Checklist
Parent Issue
See parent analysis report: #929
Related to #929