refactor(logger): eliminate logger level factory duplication with generics#6828
Merged
Conversation
6 tasks
Replace the four structurally-identical functions (makeLevelLogger, makeServerLevelLogger, newLevelLoggerFuncs, newServerLevelLoggerFuncs) and the two mirrored struct types (levelLoggerFuncs, serverLevelLoggerFuncs) with: - logFuncSet[F any] — a single generic struct that holds the info/warn/error/debug quad for any function signature F. - newLogFuncSet[F any] — a single generic factory that wires all four levels, eliminating the repeated per-level initialisation block. - levelLoggerFuncs and serverLevelLoggerFuncs are now type aliases for logFuncSet instantiated with their respective concrete signatures, so no call sites in file_logger.go, markdown_logger.go, or server_file_logger.go need to change. Adding a new log level now requires updating only one place (newLogFuncSet) instead of four. Closes #<issue>
Copilot
AI
changed the title
[WIP] Refactor duplicate logger level function patterns
refactor(logger): eliminate logger level factory duplication with generics
Jun 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the internal logger’s per-level closure wiring to remove duplicated factory/struct patterns by introducing a single generic logFuncSet + newLogFuncSet, while keeping existing call sites unchanged via type aliases.
Changes:
- Introduced generic
logFuncSet[F any]to represent the per-level (info/warn/error/debug) function bundle for any signature. - Added
newLogFuncSetgeneric factory and rewirednewLevelLoggerFuncs/newServerLevelLoggerFuncsto delegate to it (removing the duplicated make* helpers). - Converted
levelLoggerFuncs/serverLevelLoggerFuncsto type aliases overlogFuncSet[...]so downstream loggers don’t need updates.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/common.go | Consolidates per-level logger closure construction using generics and type aliases to eliminate duplicated implementations. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Comment on lines
+235
to
+237
| // logFuncSet is a generic bundle of per-level logging closures all sharing the | ||
| // same function signature F. It is the single source of truth for the | ||
| // info/warn/error/debug quad used by every logger variant. |
Collaborator
|
@copilot address review feedback |
Contributor
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.
internal/logger/common.gohad two structurally identical function pairs (makeLevelLogger/makeServerLevelLoggerandnewLevelLoggerFuncs/newServerLevelLoggerFuncs) plus two mirrored struct types (levelLoggerFuncs/serverLevelLoggerFuncs), differing only in the presence of aserverID stringparameter. Adding a new log level required changes in four places instead of two.Changes
logFuncSet[F any]— new generic struct replacing bothlevelLoggerFuncsandserverLevelLoggerFuncs; holds theinfo/warn/error/debugquad for any function signatureFnewLogFuncSet[F any]— new generic factory replacing bothnew*LevelLoggerFuncsbodies; callsmakeFunc(level)once per levellevelLoggerFuncsandserverLevelLoggerFuncsbecome aliases for their respectivelogFuncSetinstantiations; no call-site changes needed infile_logger.go,markdown_logger.go, orserver_file_logger.gomakeLevelLogger/makeServerLevelLoggerremoved — inlined into the two thinnew*wrappers that now delegate tonewLogFuncSetA new log level now requires a single entry in
newLogFuncSetinstead of four.