googollee / go-socket.io

socket.io library for golang, a realtime application framework.
Other
5.63k stars 826 forks source link

Migrating logging to the slog package #607

Closed grahamjenson closed 10 months ago

grahamjenson commented 10 months ago

structured logging will soo be part of core Golang in the slog package https://github.com/golang/go/issues/56345

This migrates the logging to that package, removing the dependency on the third party zap package. Zap can still be used with slog, but that decision should be on the importing project not the library.

Graham

erkie commented 10 months ago

How does this PR affect the log output? Do you have an example, pre-this-PR and what this PR outputs? Are they similar? Also, how does this affect the following things that previously worked:

GO_SOCKET_IO_LOG_LEVEL="error"
GO_SOCKET_IO_LOG_ENABLE="false"
GO_SOCKET_IO_DEBUG="false"

As mentioned in logging/README.md?

Just want to understand how much of a breaking change this is.

grahamjenson commented 10 months ago

I think this will be a breaking change because the log level should be decided by the importer of the package, but package level logging should still be configurable.

I will look at this soon.

grahamjenson commented 10 months ago

The envars wont work (unless the importer sets them up to) but I added back the readme and put in it a small bit about how to customize the logging with slog from this package. The core problem is that a slog logger can have multiple handlers at different levels.

I think this will be a breaking change, even if not functional. I think the only way to make it not breaking would be to set as the default slog handler as a wrapper around the previous zap logger (not sure how difficult this will be), and bring back all that code as "soon to be deprecated". That is a lot of work though and we would lose the benefits of dropping two libraries and having a much simpler logging setup.

erkie commented 10 months ago

Imo it's not that important that the functionality stays 100% the same, just that there is an easy way for the user of this library to customize the log levels. And the added documentation helps a lot with that! Great work.

RandalTeng commented 10 months ago

Thanks for your works. Little question: when this feature will release as a public version? Like v1.17.1?