[PR #15493] refactor: inject logger dependency into GenerateRoutes #15176

Open
opened 2026-04-13 01:11:58 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15493
Author: @Alfievarghese
Created: 4/11/2026
Status: 🔄 Open

Base: mainHead: refactor-global-logger


📝 Commits (1)

  • 04911b8 refactor: inject logger dependency into GenerateRoutes instead of relying on global slog.Default()

📊 Changes

4 files changed (+31 additions, -28 deletions)

View changed files

📝 server/routes.go (+3 -3)
📝 server/routes_cloud_test.go (+18 -17)
📝 server/routes_test.go (+4 -3)
📝 server/routes_web_experimental_test.go (+6 -5)

📄 Description

This PR refactors GenerateRoutes to accept an explicit *slog.Logger dependency, removing the reliance on the global slog.Default() within the registry.Local initialization. This addresses an internal TODO and improves the testability and architecture of the server routing layer.

Motivation Previously, registry.Local was initialized with slog.Default() inside GenerateRoutes. As noted in the existing code comments (now removed), it was better to pass a logger explicitly to avoid side effects and allow for better dependency injection.

Changes

server/routes.go: Updated GenerateRoutes signature to include logger *slog.Logger.
server/routes.go: Replaced slog.Default() with the provided logger when initializing registry.Local.
server/routes.go: Updated the Serve function to pass slog.Default() into the routing pipeline.
Testing: Updated several test files (routes_test.go, routes_cloud_test.go, and routes_web_experimental_test.go) to inject slog.Default() into the router setup, ensuring full compatibility with existing test suites.
Verification

Code was manually reviewed for correctness.
All affected files were updated to ensure the compilation of the server and its tests remains stable under the new function signature.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/15493 **Author:** [@Alfievarghese](https://github.com/Alfievarghese) **Created:** 4/11/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `refactor-global-logger` --- ### 📝 Commits (1) - [`04911b8`](https://github.com/ollama/ollama/commit/04911b8cc1d19fa78edff7bea8df240fa0f4101a) refactor: inject logger dependency into GenerateRoutes instead of relying on global slog.Default() ### 📊 Changes **4 files changed** (+31 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `server/routes.go` (+3 -3) 📝 `server/routes_cloud_test.go` (+18 -17) 📝 `server/routes_test.go` (+4 -3) 📝 `server/routes_web_experimental_test.go` (+6 -5) </details> ### 📄 Description This PR refactors GenerateRoutes to accept an explicit *slog.Logger dependency, removing the reliance on the global slog.Default() within the registry.Local initialization. This addresses an internal TODO and improves the testability and architecture of the server routing layer. Motivation Previously, registry.Local was initialized with slog.Default() inside GenerateRoutes. As noted in the existing code comments (now removed), it was better to pass a logger explicitly to avoid side effects and allow for better dependency injection. Changes server/routes.go: Updated GenerateRoutes signature to include logger *slog.Logger. server/routes.go: Replaced slog.Default() with the provided logger when initializing registry.Local. server/routes.go: Updated the Serve function to pass slog.Default() into the routing pipeline. Testing: Updated several test files (routes_test.go, routes_cloud_test.go, and routes_web_experimental_test.go) to inject slog.Default() into the router setup, ensuring full compatibility with existing test suites. Verification Code was manually reviewed for correctness. All affected files were updated to ensure the compilation of the server and its tests remains stable under the new function signature. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 01:11:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#15176