cloud-sql-proxy icon indicating copy to clipboard operation
cloud-sql-proxy copied to clipboard

refactor: replace zap with slog

Open danielandersson opened this issue 11 months ago • 4 comments

This PR replaces the third-party Zap logging library with Go's standard library slog package for structured logging. This change reduced the number of dependencies while maintaining the same logging functionality and format.

Fixes #2120

Changes

  • Removed dependencies on go.uber.org/zap and go.uber.org/zap/zapcore
  • Added usage of Go's standard library log/slog package
  • Simplified the StdLogger structure by combining infoLog and debugLog into a single stdLog
  • Refactored the StructuredLogger to use slog.Logger instead of Zap's SugaredLogger
  • Modified the NewStructuredLogger function to use slog handlers and configuration
  • Added a new replaceAttr function to maintain compatibility with Google Cloud Logging format
  • Ensured that log messages continue to adhere to the LogEntry format for Google Cloud Logging

danielandersson avatar Apr 04 '25 15:04 danielandersson

Thanks @danielandersson 👏

I will take a look at this in the coming days 😄

jackwotherspoon avatar Apr 04 '25 19:04 jackwotherspoon

@hessjcg mind taking a look at this one?

Also @enocom you might also want to take a look as a similar change would probably be added to AlloyDB Proxy 😄

jackwotherspoon avatar Apr 24 '25 14:04 jackwotherspoon

Some minor style nits. Otherwise LGTM.

@hessjcg we should manually verify the before and after logs just to be certain this doesn't break the existing structured logging. I think it's correct, but better to double check.

Thanks for the review, all of your feedback should have been addressed with 0946cd0c922c7e0d24912087bc9469e497f42e78.

danielandersson avatar May 12 '25 22:05 danielandersson

/gcbrun

hessjcg avatar May 22 '25 16:05 hessjcg

/gcbrun

hessjcg avatar Aug 12 '25 20:08 hessjcg