
▲ 34 r/golang
Has anyone else switched back to a third party package from slog
I'm generally a big fan of trying to use the stdlib where available, but have found slog a bit lacking. Mainly:
- Writing middleware that attaches things like trace/span IDs to logs requires quite a bit of code, and doesn't even work as expected (to me) when combined with
logger.WithGroup- https://github.com/golang/go/issues/58243#issuecomment-1692305833 slog.Anyattribute is used for values implementing eitherslog.LogValuerOR values intrinsically understood by the log handler. As a result I have lots ofslog.Anycalls in my codebase that are not subject to the same static typing as the rest of my code, and which may only work with specific handler implementations. This is particularly bad when compared to things like zap (which separates Object fields from reflection based fields) or zerolog (which separates Object fields fields reflection based fields)- The lack of list/array attributes seems like a pretty big gap for common use cases, such as logging an array of json:api errors or gRPC status details (or at least a subset of their fields) in a way that is portable across handlers - https://github.com/golang/go/issues/71088
This is mainly in the context of developing a web app, so maybe others have had better luck in other contexts, but I think I'm just going to stick to zap/zerolog and avoid these headaches.
u/2facetherapper — 2 days ago