Skip to content

Deduplicate logger startup and shutdown wiring with shared registries#7575

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-logger-boilerplate
Jun 15, 2026
Merged

Deduplicate logger startup and shutdown wiring with shared registries#7575
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-logger-boilerplate

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

The logger package had repeated startup/shutdown glue across five logger types: per-type global init/close wrappers were already backed by shared generic helpers, but gateway/proxy startup and CloseAllLoggers still relied on manually duplicated wiring. This change centralizes that orchestration without changing the public logger APIs or fallback behavior.

  • What changed

    • Added shared registries for:
      • gateway logger initialization
      • proxy logger initialization
      • global logger shutdown
    • Replaced the hand-written sequences in InitGatewayLoggers, InitProxyLoggers, and CloseAllLoggers with registry iteration.
  • Why this is smaller and safer

    • Keeps each logger’s explicit Init* / Close* entry points intact.
    • Moves the “which loggers participate, and in what order” concern into one place.
    • Reduces the chance of adding a new logger type but missing one of the package-level startup/cleanup paths.
  • Package docs and coverage

    • Updated logger package documentation to note the centralized registry model.
    • Added focused tests that assert the expected registry membership and ordering for gateway, proxy, and global close paths.
  • Shape of the refactor

    type loggerInitEntry struct {
        name string
        init func(logDir string) error
    }
    
    func InitGatewayLoggers(logDir string) {
        initLoggerSet(logDir, gatewayLoggerInitializers)
    }
    
    func CloseAllLoggers() error {
        return closeLoggerSet(globalLoggerClosers)
    }

GitHub Advanced Security started work on behalf of lpcox June 15, 2026 13:41 View session
GitHub Advanced Security finished work on behalf of lpcox June 15, 2026 13:42
Copilot AI changed the title [WIP] Refactor logger initialization to remove duplicate code Deduplicate logger startup and shutdown wiring with shared registries Jun 15, 2026
Copilot finished work on behalf of lpcox June 15, 2026 13:48
Copilot AI requested a review from lpcox June 15, 2026 13:48
GitHub Advanced Security started work on behalf of lpcox June 15, 2026 14:06 View session
GitHub Advanced Security finished work on behalf of lpcox June 15, 2026 14:07
@lpcox lpcox marked this pull request as ready for review June 15, 2026 14:34
Copilot AI review requested due to automatic review settings June 15, 2026 14:34

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 internal/logger startup/shutdown orchestration by centralizing the “which loggers participate, and in what order” logic into shared registries, while preserving the existing per-logger Init*/Close* public APIs and non-fatal startup warning behavior.

Changes:

  • Introduces shared gateway/proxy initializer registries and a global closer registry, plus small helpers to iterate them.
  • Replaces hand-written sequences in InitGatewayLoggers, InitProxyLoggers, and CloseAllLoggers with registry iteration.
  • Adds tests to assert registry membership and ordering; updates package documentation to describe the registry model.
Show a summary per file
File Description
internal/logger/registry.go Adds the shared initializer/closer registries and iteration helpers.
internal/logger/init.go Switches gateway/proxy initialization to use the shared registries.
internal/logger/init_test.go Adds tests asserting registry membership and ordering.
internal/logger/global_helpers.go Switches CloseAllLoggers to use the shared closer registry.
internal/logger/common.go Updates package documentation to describe the registry-based orchestration model.

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 02bdc3b into main Jun 15, 2026
46 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-logger-boilerplate branch June 15, 2026 15:25
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.

3 participants