Replace zap with slog; Replace logging wrappers with slog
- [x] Read the Contributing document.
Summary
gorouter uses a very outdated zap version from 2016 for logging. This Pull-Request introduces required code changes to use slog as the logging frontend, together with a zap handler via zapslog. Slog provides a stable frontend, while we keep using zap with its configuration as the backend.
Both the gorouter logger and the lager logger (used for initializing the UAA Token Fetcher) used zap logger wrappers. This Pull-Request replaces the logger wrapper with direct use of slog.Logger. A thin library is provided to keep it compatible with the code. The library provides the functions CreateLogger and CreateLoggerWithSource to create a logger that subsequently writes data into the data field, and optionally sets the source field in the log's root. The library also has functions to dynamically set the WriteSyncer, which is required for tests, and to dynamically set the logging level and timestamp format.
With the removal of the Logger interface, all occurrences of the FakeLogger have been replaced with an slog.Logger based TestLogger.
Additionally, some test refactoring and code reformatting has been done.
Backward Compatibility
Breaking Change? No
This Pull-Request requires https://github.com/cloudfoundry/routing-release/pull/434 for updating zap dependencies.
The zap handler configuration has been kept, so the log message format does not change. Workarounds for differing behavior of the slog.Logger frontend have been found and implemented. There are quite a lot of tests on log messages in the code, an additional end-to-end test with a deployment of this code did not show any differences compared to the old implementation.