Skip to content

refactor: replace direct slog usage with api.Logger in handlers#808

Open
sumitakhuli wants to merge 1 commit intoOneBusAway:mainfrom
sumitakhuli:fix/replace-slog-with-api-logger
Open

refactor: replace direct slog usage with api.Logger in handlers#808
sumitakhuli wants to merge 1 commit intoOneBusAway:mainfrom
sumitakhuli:fix/replace-slog-with-api-logger

Conversation

@sumitakhuli
Copy link
Copy Markdown

Description

Fixes #694

This PR refactors several REST API handlers to eliminate direct slog usages and replace them with the contextual api.Logger.

Previously, some handlers bypassed the structured logging configuration by calling slog.Warn(), slog.Info(), or slog.Error() directly, or by using slog.String rather than passing alternating key-value string arguments to the context logger. This change enforces consistency with other handlers (e.g., trips_for_route_handler.go) to ensure all log output routes properly through the *RestAPI receiver.

Changes Made

  • trip_details_handler.go: Replaced direct slog.Warn events mapped to api.Logger.Warn. Removed slog.String wrappers in favor of variadic key-value arguments.
  • report_problem_with_stop_handler.go & report_problem_with_trip_handler.go: Removed default slog.Default() fallbacks. Overhauled logging.LogOperation and logging.LogError logic to invoke corresponding .Info() and .Error() calls cleanly onto api.Logger.
  • Test Files (trip_for_vehicle_handler_test.go, stops_for_route_handler_test.go): Swapped standard slog.New logger instantiations in favor of logging.NewStructuredLogger, dropping the log/slog imports across the rest api bounds.

Acceptance Criteria Met

  • Audited all *_handler.go files in internal/restapi/ for direct slog usage.
  • Replaced all direct slog.Warn(), slog.Info(), slog.Error() calls with the equivalent api.Logger.Warn(), api.Logger.Info(), api.Logger.Error() calls.
  • Verified grep -r "slog\." internal/restapi/*handler*.go returns exactly zero matches.
  • make test passes (confirmed logic & syntax integrity).
  • make lint passes.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 31, 2026

CLA assistant check
All committers have signed the CLA.

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.

Standardize logging across REST API handlers

2 participants