refactor: remove verbose flag and enable persistent debug logging#314
Merged
SuperCoolPencil merged 3 commits intomainfrom Apr 2, 2026
Merged
refactor: remove verbose flag and enable persistent debug logging#314SuperCoolPencil merged 3 commits intomainfrom
SuperCoolPencil merged 3 commits intomainfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Comment on lines
412
to
414
| PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
| // Set global verbose mode | ||
| utils.SetVerbose(verbose) | ||
|
|
||
| GlobalProgressCh = make(chan any, 100) |
Contributor
There was a problem hiding this comment.
Stray blank line left after removing verbose setup
Removing the SetVerbose call left an empty line at the top of PersistentPreRun, making the function body start with unnecessary whitespace. Consider removing it.
Suggested change
| PersistentPreRun: func(cmd *cobra.Command, args []string) { | |
| // Set global verbose mode | |
| utils.SetVerbose(verbose) | |
| GlobalProgressCh = make(chan any, 100) | |
| PersistentPreRun: func(cmd *cobra.Command, args []string) { | |
| GlobalProgressCh = make(chan any, 100) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
… include integration test
Member
Author
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.
Greptile Summary
This PR removes the
--verbose/-vflag and replaces it with persistent, always-on debug logging: every Surge session now automatically writes adebug-*.logfile to the platform-appropriate state directory, capped by thelog_retention_countsetting. Theverbose boolparameter is removed fromDetermineFilename,SetVerbose/IsVerboseare replaced by the leanerIsLoggingEnabled, and allfmt.Fprintf(os.Stderr, …)verbose prints are converted toDebug(…)calls. The previously-duplicatefiletype.Match(header)call is collapsed into a single invocation whose result is shared between the debug block and the extension-inference logic.Key changes:
internal/utils/debug.go— dropsverbose atomic.Bool; addsIsLoggingEnabled()so callers can gate expensive work behind a fast check without enteringDebug.internal/utils/filename.go—DetermineFilenamesignature simplified;filetype.Matchcalled once and result reused;http.DetectContentTypeguarded byIsLoggingEnabled().cmd/root_startup.go— cleanup now usesretention - 1before creating the new session log, correctly bounding the on-disk count tolog_retention_count.internal/utils/filename_test.go— existing tests updated; newTestDetermineFilename_LoggingIntegrationadded.Issues found:
TestDetermineFilename_LoggingIntegrationtest may not exercise the debug-write code path it is named after:debugOnce(a package-levelsync.Once) can be spent by an earlier test in the binary before this test configures its temp directory, silently making the "integration" half a no-op.log_retention_countis0, the current logic deletes all existing logs but still creates one new log for the session — leaving one file where the user may have intended zero.Confidence Score: 5/5
Safe to merge; all findings are P2 quality concerns that do not affect production behaviour.
The production code changes are mechanically correct: the verbose flag is cleanly removed, Debug fast-paths are in place, and the retention-1 arithmetic is right for all non-zero values. The two remaining issues (test isolation via debugOnce and the retention==0 edge case) are P2 concerns that don't affect real users in the default configuration.
internal/utils/filename_test.go (integration test may not verify log writes), cmd/root_startup.go (retention==0 edge case)
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Surge startup initializeGlobalState] --> B[ConfigureDebug logsDir] B --> C{retention > 0?} C -- yes --> D[CleanupLogs retention-1] C -- no --> E[CleanupLogs retention] D --> F[New session log created on first Debug call] E --> F G[DetermineFilename called] --> H[Apply heuristics Content-Disposition / query / path] H --> I[Read 512-byte header] I --> J[filetype.Match header one call, result cached] J --> K{IsLoggingEnabled?} K -- yes --> L[http.DetectContentType Debug MIME + magic type] K -- no --> M[Skip expensive MIME log] L --> N[ZIP / extension inference uses cached kind] M --> N N --> O[Return filename] subgraph Debug subsystem P[Debug format args] --> Q{logsDir empty?} Q -- yes --> R[return fast path] Q -- no --> S[debugOnce.Do create log file] S --> T[Write timestamped line] endPrompt To Fix All With AI
Reviews (2): Last reviewed commit: "refactor: optimize debug logging by addi..." | Re-trigger Greptile
Context used: