Skip to content

refactor(logger): replace 12 boilerplate log-level wrappers with var aliases#8502

Merged
lpcox merged 4 commits into
mainfrom
copilot/duplicate-code-log-level-wrapper
Jul 2, 2026
Merged

refactor(logger): replace 12 boilerplate log-level wrappers with var aliases#8502
lpcox merged 4 commits into
mainfrom
copilot/duplicate-code-log-level-wrapper

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Three logger files each declared four identical one-liner exported wrappers (LogInfo, LogWarn, LogError, LogDebug per sink) that did nothing but forward to a struct field. The levelLoggerFuncs struct already held the closure — the wrapper functions were pure boilerplate.

Changes

  • file_logger.go, markdown_logger.go, server_file_logger.go: Replace 4 func declarations per file with a var (...) block that aliases the struct fields directly:
// Before — 3-line boilerplate × 12
func LogInfo(category, format string, args ...interface{}) {
    fileLevelLoggers.info(category, format, args...)
}

// After — one field alias per level
var (
    LogInfo  = fileLevelLoggers.info
    LogWarn  = fileLevelLoggers.warn
    LogError = fileLevelLoggers.error
    LogDebug = fileLevelLoggers.debug
)
  • global_state.go: Rename the doc section from "Quad-Function Pattern" → "Quad-Var Pattern", update the new-level checklist to say "add a var alias" instead of "add an exported wrapper", fix stale common.go references (the pattern doc lives in global_state.go).

Semantics

Callers are unaffected — same call syntax, same type signatures. Go's dependency-ordered initialization guarantees fileLevelLoggers is populated before the exported vars are set, and the logFuncs map (which references LogInfo etc.) is initialized last in the chain.

Copilot AI linked an issue Jul 2, 2026 that may be closed by this pull request
6 tasks
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 22:32 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 22:33
Copilot AI added 2 commits July 2, 2026 22:40
Convert the three quad-function sets (LogInfo/LogWarn/LogError/LogDebug,
LogInfo/Warn/Error/DebugToMarkdown, LogInfo/Warn/Error/DebugToServer)
from exported function declarations to exported package-level var aliases
that point directly to the corresponding per-level closure in the
existing *LevelLoggers struct instances.

Before (3 × 4 functions = 12 identical 3-line boilerplate wrappers):
    func LogInfo(category, format string, args ...interface{}) {
        fileLevelLoggers.info(category, format, args...)
    }

After (3 var blocks, one field alias each):
    var LogInfo = fileLevelLoggers.info

Behaviour is identical: callers still call LogInfo(...) with the same
signature. The logFuncs map in global_state.go continues to reference
LogInfo/LogWarn/LogError/LogDebug, and Go's dependency-ordered init
guarantees those vars are set before logFuncs is initialized.

Also fixes stale 'common.go' references in per-sink header comments
(the pattern doc lives in global_state.go, not common.go) and updates
the 'Log-Level Quad-Function Pattern' section in global_state.go to
describe the new var-alias design.

Closes #8476
Copilot AI changed the title [WIP] Refactor duplicate logger functions into a single wrapper refactor(logger): replace 12 boilerplate log-level wrappers with var aliases Jul 2, 2026
Copilot finished work on behalf of lpcox July 2, 2026 22:42
Copilot AI requested a review from lpcox July 2, 2026 22:42
@lpcox lpcox marked this pull request as ready for review July 2, 2026 22:42
Copilot AI review requested due to automatic review settings July 2, 2026 22:42
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 22:44 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 22:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the internal/logger package by replacing 12 exported, per-level wrapper functions (Info/Warn/Error/Debug across multiple sinks) with exported var aliases to the underlying per-level closures, and updates the corresponding documentation in global_state.go.

Changes:

  • Replace per-level exported wrapper funcs with exported var aliases in file_logger.go, markdown_logger.go, and server_file_logger.go.
  • Update the pattern documentation in global_state.go to describe the new “Quad-Var” approach and adjust the “add a new level” checklist accordingly.
Show a summary per file
File Description
internal/logger/file_logger.go Replaces LogInfo/LogWarn/LogError/LogDebug exported wrapper functions with exported var aliases.
internal/logger/markdown_logger.go Replaces Log*ToMarkdown exported wrapper functions with exported var aliases.
internal/logger/server_file_logger.go Replaces Log*ToServer exported wrapper functions with exported var aliases.
internal/logger/global_state.go Updates the documented “Quad-*” pattern and checklist to reflect var aliasing.

Review details

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 5
  • Review effort level: Low

Comment thread internal/logger/file_logger.go Outdated
Comment thread internal/logger/markdown_logger.go Outdated
Comment on lines +194 to +198
var (
// LogInfoToMarkdown logs to both regular and markdown loggers.
LogInfoToMarkdown = markdownLevelLoggers.info

// LogWarnToMarkdown logs to both regular and markdown loggers.
func LogWarnToMarkdown(category, format string, args ...interface{}) {
markdownLevelLoggers.warn(category, format, args...)
}
// LogWarnToMarkdown logs to both regular and markdown loggers.
Comment thread internal/logger/server_file_logger.go Outdated
Comment on lines +154 to +158
var (
// LogInfoToServer logs an informational message to the server-specific log file.
LogInfoToServer = serverLevelLoggers.info

// LogWarnToServer logs a warning message to the server-specific log file.
func LogWarnToServer(serverID, category, format string, args ...interface{}) {
serverLevelLoggers.warn(serverID, category, format, args...)
}
// LogWarnToServer logs a warning message to the server-specific log file.
Comment thread internal/logger/global_state.go Outdated
Comment on lines +199 to +203
// Log-Level Quad-Var Pattern
//
// Three sets of four public functions — one set per logger variant — share an
// identical structure where each exported one-liner delegates to an unexported
// per-level closure registered by helpers in this file:
// Three sets of four exported package-level vars — one set per logger variant —
// are each a direct alias of the corresponding per-level closure field on the
// sink's levelLoggerFuncs (or serverLevelLoggerFuncs) instance:
Comment on lines 223 to 230
// If a new LogLevel constant is ever added (e.g., LogLevelTrace), update all
// required locations to keep the public API consistent:
// 1. Add a new entry to the logFuncs map in this file.
// 2. Update newLogFuncSet in this file.
// 3. In file_logger.go: add an exported wrapper (see LogInfo pattern).
// 4. In markdown_logger.go: add an exported wrapper (see LogInfoToMarkdown pattern).
// 5. In server_file_logger.go: add an exported wrapper (see LogInfoToServer pattern).
// 3. In file_logger.go: add a new var alias in the exported var block (see LogInfo pattern).
// 4. In markdown_logger.go: add a new var alias in the exported var block (see LogInfoToMarkdown pattern).
// 5. In server_file_logger.go: add a new var alias in the exported var block (see LogInfoToServer pattern).
// 6. Update TestLogLevelWrappers_CoverAllRegisteredLevels in log_level_wrappers_test.go.
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 22:46 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 22:47
@lpcox

lpcox commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Reverted all four files in the latest commit. file_logger.go, markdown_logger.go, and server_file_logger.go are back to exported func wrappers, and global_state.go is back to documenting the "Quad-Function Pattern" with the func-based checklist.

Copilot finished work on behalf of lpcox July 2, 2026 22:51
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 22:51 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 22:52
@lpcox lpcox merged commit 9b248c2 into main Jul 2, 2026
26 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-log-level-wrapper branch July 2, 2026 23:02
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: Log-Level Quad-Function Wrapper Boilerplate

3 participants