Conversation
davidzhao
left a comment
There was a problem hiding this comment.
Did we have to change all of the logger usage internally to slog?
IMO it makes sense to use it as the interface, and when interfacing with external clients. But using slog internally in the code base seems to be a step backwards for the following reasons:
- It breaks a certain consistency within our Go codebase. Everywhere else we are using protocol logger
- We would lose features, particularly with WithValues, WithComponent, etc
Only in the SDK, yes. To be clear, using Conversion is currently only one way If we want to allow passing custom
This depends on if we will adopt it long term. It could be just a temporary inconsistency. In practice (if I understand correctly), we mostly use Zap under the hood, which has slog adapter as well. So in general we could decide to move to slog as a main log interface eventually. That would remove the need to maintain our own logger interface. There are too many loggers in the wild already 😅 But that's just as an option, it's not directly related to the PR.
We do lose Zap-specific things like package logger
func WithItemSampler(log *slog.Logger) *slog.LoggerIf the underlying logger is not Zap it will just return the same logger with no changes. This will work for Logr, for example, but also for any other log package out there. So it's definitely worth a separate discussion about the long term plans. I could make a separate DD/proposal with all the details that we can discuss. But for now this PR only changes client-facing SDK to use the logger from Go stdlib. I think eventually most libraries will converge to using that interface anyway, so I wanted to see how invasive it would be to switch. Turns out it's not. |
Go SDK will be used in other projects, thus it makes sense to use standard structured logging instead of our own one.
livekit/protocol#668 added support for
slogto the protocol'sloggerpackage. This change propagates it to the SDK.For our own projects, calling
logger.SetLoggerwill automatically setsloglogger as well, making this change backward-compatible.Also, add
SetLoggerto the most important structs of the package, allowing to associate additional metadata with RTC logs.