Document logger Close() pattern and fix import cycle#461
Merged
Conversation
- Added comprehensive documentation to internal/logger/common.go explaining the Close() pattern for logger types - Fixed import cycle between internal/logger and internal/tty packages by removing debug logging from tty/container.go - Fixed duplicate intPtr() declaration in config test files The mount validation test failure is a pre-existing issue unrelated to the logger documentation task. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate Close() methods in logger classes
Document logger Close() pattern and fix import cycle
Jan 25, 2026
This was referenced Jan 25, 2026
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.
Issue #436 identified minimal duplication in logger Close() methods (5-14 lines per type) and recommended documentation over refactoring. The pattern is idiomatic Go: wrapper methods that add context to a shared
closeLogFile()helper.Changes
Documentation (
internal/logger/common.go)closeLogFile()Build Fixes
internal/tty/container.go: Removed logger import to breakinternal/logger↔internal/ttycycleinternal/config/validation_test.go: Removed duplicateintPtr()declarationBoth were blocking compilation.
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:
nonexistent.local/tmp/go-build2955798797/b269/launcher.test /tmp/go-build2955798797/b269/launcher.test -test.testlogfile=/tmp/go-build2955798797/b269/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go pull.rebase /usr/local/.ghcu-lang=go1.25(dns block)/tmp/go-build1623642188/b269/launcher.test /tmp/go-build1623642188/b269/launcher.test -test.testlogfile=/tmp/go-build1623642188/b269/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1775386590/b265/vet.cfg go 4hElLqVi8 x_amd64/compile(dns block)this-host-does-not-exist-12345.com/tmp/go-build2955798797/b278/mcp.test /tmp/go-build2955798797/b278/mcp.test -test.testlogfile=/tmp/go-build2955798797/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -b ontext.go 64/pkg/tool/linu-lang=go1.25 --depth 2 REDACTED 64/pkg/tool/linu/tmp/go-build2955798797/b098/vet.cfg conf�� _.a ternal/impl/impl-c=4 64/pkg/tool/linu-nolocalimports user.email(dns block)/tmp/go-build1623642188/b278/mcp.test /tmp/go-build1623642188/b278/mcp.test -test.testlogfile=/tmp/go-build1623642188/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1775386590/b274/vet.cfg ache/go/1.25.6/x64/src/runtime/cgo1.25.6 rJ3W/LomnKYz78ppfT8whrJ3W x_amd64/vet(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] Duplicate Code Pattern: Logger Close() Method Duplication</issue_title>
<issue_description># 🔍 Duplicate Code Pattern: Logger Close() Method Duplication
Part of duplicate code analysis: #435
Summary
The three logger types implement nearly identical
Close()methods that follow the same pattern: acquire mutex, callcloseLogFile()helper, release mutex. While the duplication is minimal (6-8 lines per method), it represents an opportunity for interface-based abstraction.Duplication Details
Pattern: Logger Close() Methods
internal/logger/file_logger.go(lines 58-62, 5 lines)internal/logger/jsonl_logger.go(lines 59-63, 5 lines)internal/logger/markdown_logger.go(lines 67-80, 14 lines)Code Comparison:
FileLogger.Close() (5 lines):
JSONLLogger.Close() (5 lines):
MarkdownLogger.Close() (14 lines - more complex):
Note: MarkdownLogger is an exception - it needs special cleanup logic to write the footer before closing.
Impact Analysis
Maintainability
closeLogFile()helper incommon.go(lines 23-36) consolidates the actual closing logicBug Risk
closeLogFile()helper, ensuring consistent behaviorCode Bloat
Refactoring Recommendations
Option 1: Interface with Default Implementation (Go 1.23+)
Note: This requires Go 1.23+ for interface with methods. Consider carefully before implementing.
Benefits:
Drawbacks:
Estimated effort: 2-3 hours (not recommended given low value)
Option 2: Accept the Pattern (Recommended)
Recommendation: Do not refactor - this level of duplication is acceptable and idiomatic in Go.
Rationale:
closeLogFile()helper already eliminates the complex logic**What has been do...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.