Skip to content

Centralize logger level wrapper registration#6752

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-logger-levels
May 30, 2026
Merged

Centralize logger level wrapper registration#6752
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-logger-levels

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

The logger package repeated the same Info/Warn/Error/Debug level-binding boilerplate across the unified, markdown, and server logger variants. This change pulls the per-level closure registration into shared helpers while preserving the existing exported logging APIs.

  • What changed

    • Added shared level-registration helpers in internal/logger/common.go for:
      • standard logger signatures
      • server-scoped logger signatures
    • Replaced per-file logInfo/logWarn/logError/logDebug var blocks with a single helper-backed struct per logger type.
  • Affected logger APIs

    • Unified logger wrappers now dispatch through fileLevelLoggers
    • Markdown logger wrappers now dispatch through markdownLevelLoggers
    • Server logger wrappers now dispatch through serverLevelLoggers
  • Behavioral scope

    • Exported functions remain unchanged:
      • LogInfo/LogWarn/LogError/LogDebug
      • LogInfoToMarkdown/...
      • LogInfoToServer/...
    • The refactor is limited to internal level wiring; call sites and signatures stay stable.
  • Test coverage

    • Added focused tests for the shared helper constructors to verify the expected LogLevel bindings.
    • Kept the existing wrapper-coverage test to ensure all registered levels still have public wrappers.
type levelLoggerFuncs struct {
	info  func(category, format string, args ...interface{})
	warn  func(category, format string, args ...interface{})
	error func(category, format string, args ...interface{})
	debug func(category, format string, args ...interface{})
}

var fileLevelLoggers = newLevelLoggerFuncs(logWithLevel)

Copilot AI changed the title [WIP] Fix duplicate logger level function boilerplate Centralize logger level wrapper registration May 30, 2026
Copilot finished work on behalf of lpcox May 30, 2026 13:59
Copilot AI requested a review from lpcox May 30, 2026 13:59
@lpcox lpcox marked this pull request as ready for review May 30, 2026 14:00
Copilot AI review requested due to automatic review settings May 30, 2026 14:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 centralizes the logger package’s repeated Info/Warn/Error/Debug closure wiring while preserving the existing exported logging APIs.

Changes:

  • Added shared helper structs/constructors for standard and server-scoped level loggers.
  • Updated file, markdown, and server logger wrappers to dispatch through centralized helper-backed structs.
  • Added focused tests verifying helper constructors bind the expected LogLevel values.
Show a summary per file
File Description
internal/logger/common.go Adds centralized level logger helper types and constructors.
internal/logger/file_logger.go Replaces per-level file logger closures with fileLevelLoggers.
internal/logger/markdown_logger.go Replaces per-level markdown logger closures with markdownLevelLoggers.
internal/logger/server_file_logger.go Replaces per-level server logger closures with serverLevelLoggers.
internal/logger/log_level_wrappers_test.go Adds tests for centralized helper level bindings.

Copilot's findings

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 0

@lpcox lpcox merged commit 35b9d8f into main May 30, 2026
29 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-fix-logger-levels branch May 30, 2026 14:03
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: Logger Level Function Boilerplate Across Logger Types

3 participants