-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: compatibility with log/slog #98
Conversation
In Go 1.21 a new structured logging package was added. This feature adds basic compatibility between lager and log/slog. This reduces the friction of mixing code that uses lager with code that uses log/slog.
Hi @blgm I'm getting some failures when running the tests, could you take a look:
|
I think that if we are going to add the slog compatibility, it would make sense to lock go.mod to go1.21 and remove build flags for go as well. |
Hi @MarcPaquette, I think this is because your system is generating timestamps slightly differently. I've added a commit that will make the tests a bit more flexible in what they match. Let me know if it works for you. And if it doesn't work, feel free to hack the regular expression until it does. @winkingturtle-vmw regarding forcing Go 1.21, that's really a trade-off of being aggressively forward looking vs supporting folks on older Go versions. When I've tried to be aggressively forward looking in the past, I've always found that there were folks who had reasons for using older versions - including versions of Go that are long out of support. So these days I look for an opportunity to make progress while breaking as few folks as possible. I don't think there's a right and wrong here, it's just a question of how you want to handle it. It's possible to support Go 1.21 functionality while maintaining support for older versions by using build flags. I agree that it's ugly. And I'm happy to make the update that you suggest, I'm just flagging that it may break a lot of folks. |
I think it's safe to lock go.mod to Go1.21. Every runtime component has been bumped to Go1.21 e.g. diego-release and that's where we use this library the most. If anyone has any other thoughts, please share. Most folks that are on older versions of this library (code.cloudfoundry.org/lager), are using the old import path and will not be getting any new updates on this repo. |
Any progress on merging this? Our team is working on a new component and would prefer to use Golang's This compatibility feature would be handy for us. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks! |
Will there be a new release cut anytime soon? |
I just tagged v3.0.3 with the changes from this PR. |
Thank you @winkingturtle-vmw and @MarcPaquette @aramprice the slog stuff is all a bit new. I’d be interested in any feedback you have on the experience. |
I'll let you all know if we encounter any rough edges. From a purely stylistic perspective it might be nice to have a one-liner option for converting. Something like: var *slog.Logger l = codeThatReturnsSlog()
lagerLogger := lager.NewLoggerWithSink("my-lager-logger", lager.NewSlogSink(l))
// or even
lagerLogger := lager.NewLoggerFromSlog(l)
codeThatAcceptsLagerLoger(lagerLogger) |
In Go 1.21 a new structured logging package was added. This feature adds basic compatibility between lager and log/slog. This reduces the friction of mixing code that uses lager with code that uses log/slog.