Skip to content

Refactor logger sink wrappers to share level-based dispatch - #9700

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-log-functions
Jul 20, 2026
Merged

Refactor logger sink wrappers to share level-based dispatch#9700
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-fix-log-functions

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

The logger package had parallel LogXxx and LogXxxToMarkdown wrapper families with the same per-level delegation shape, which made sink changes fan out across multiple files. This change keeps the public logging APIs intact while centralizing file/markdown dispatch behind shared sink helpers.

  • Shared sink dispatch

    • Added a generic level-sink abstraction in internal/logger/global_state.go.
    • Introduced a single dispatcher that fans one log event out to multiple sinks in order.
  • File and markdown wrappers

    • Reworked logWithLevel to dispatch through the shared sink helper instead of owning its own global logger access path.
    • Reworked logWithMarkdown to use the same dispatcher for unified-file + markdown fan-out.
  • Behavior preserved

    • Public wrappers such as LogInfo, LogWarn, LogInfoToMarkdown, and LogWarnToMarkdown remain unchanged.
    • Existing file/markdown dual-write behavior continues to flow through the same top-level APIs.
  • Focused coverage

    • Added a targeted unit test for the shared sink dispatcher to lock in ordering and multi-sink fan-out behavior.
    • Updated package docs to reflect the centralized dispatch path.
func logWithMarkdown(level LogLevel, category, format string, args ...interface{}) {
	dispatchLevelToSinks(level, category, format, args, fileLevelSink, markdownLevelSink)
}

Copilot AI changed the title [WIP] Refactor duplicate logging functions to reduce code duplication Refactor logger sink wrappers to share level-based dispatch Jul 20, 2026
Copilot finished work on behalf of lpcox July 20, 2026 13:52
Copilot AI requested a review from lpcox July 20, 2026 13:52
@lpcox
lpcox marked this pull request as ready for review July 20, 2026 15:02
Copilot AI review requested due to automatic review settings July 20, 2026 15:02

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

Centralizes file and markdown logger dispatch while preserving public APIs and existing dual-write behavior.

Changes:

  • Adds reusable level-based sink adapters and ordered fan-out.
  • Refactors file and markdown wrappers to use shared dispatch.
  • Adds dispatcher coverage and updates documentation.
Show a summary per file
File Description
internal/logger/global_state.go Adds shared sink abstraction and dispatcher.
internal/logger/file_logger.go Routes file logging through shared dispatch.
internal/logger/markdown_logger.go Shares file/markdown fan-out logic.
internal/logger/helper_functions_test.go Tests ordered multi-sink dispatch and nil handling.
internal/logger/doc.go Documents centralized dispatch.

Review details

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Medium

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: Parallel LogXxx / LogXxxToMarkdown Function Families

3 participants