refactor(logger): replace 12 boilerplate log-level wrappers with var aliases#8502
Merged
Conversation
6 tasks
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
Contributor
There was a problem hiding this comment.
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 exportedvaraliases infile_logger.go,markdown_logger.go, andserver_file_logger.go. - Update the pattern documentation in
global_state.goto 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 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 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 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. |
Collaborator
|
@copilot address review feedback |
Contributor
Author
Reverted all four files in the latest commit. |
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.
Three logger files each declared four identical one-liner exported wrappers (
LogInfo,LogWarn,LogError,LogDebugper sink) that did nothing but forward to a struct field. ThelevelLoggerFuncsstruct already held the closure — the wrapper functions were pure boilerplate.Changes
file_logger.go,markdown_logger.go,server_file_logger.go: Replace 4funcdeclarations per file with avar (...)block that aliases the struct fields directly: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 stalecommon.goreferences (the pattern doc lives inglobal_state.go).Semantics
Callers are unaffected — same call syntax, same type signatures. Go's dependency-ordered initialization guarantees
fileLevelLoggersis populated before the exported vars are set, and thelogFuncsmap (which referencesLogInfoetc.) is initialized last in the chain.