Skip to content
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

Create slogr implementation for slog package #171

Closed
Dentrax opened this issue Feb 11, 2023 · 6 comments
Closed

Create slogr implementation for slog package #171

Dentrax opened this issue Feb 11, 2023 · 6 comments
Assignees

Comments

@Dentrax
Copy link

Dentrax commented Feb 11, 2023

slog is a new standard library package which could provide structured logging with levels. 1

I'd be great to create a new separate repo called slogr for slog logger. Any thoughts on this?

Footnotes

  1. https://www.youtube.com/watch?v=gd_Vyb5vEw0

@pohly
Copy link
Contributor

pohly commented Feb 11, 2023

Do we need a separate repo for it?

Pro: versioning separately from go-logr/logr
Con: one more repo to maintain, like funcr it won't add dependencies

I think the versioning aspect is significant enough that it should be a separate repo.

@Dentrax: do you want to work on such a slogr LogSink?

@Dentrax
Copy link
Author

Dentrax commented Feb 11, 2023

Do we need a separate repo for it?

I'm not so sure, just noticed there are a bunch of logger implementations separated along different repos: https://github.com/go-logr/logr#implementations-non-exhaustive

do you want to work on such a slogr LogSink?

Not making promises, but maybe I can work on this. But don't know where to start. Is there any documentation for this?

@pohly
Copy link
Contributor

pohly commented Feb 11, 2023

So this is basically a feature request to create an slogr. That's fine and definitely something that someone should do, but let's wait with creating the repo until there is something that we can put there.

The other loggers could serve as example. There's no dedicated documentation for "how to write a LogSink".

@pohly
Copy link
Contributor

pohly commented Feb 12, 2023

Such an slogr implementation is probably going to be more complicated. We also need to consider how libraries using logr will interact with binaries using slog. For example, consider an binary which creates a slog logger using some kind of implementation, then installs it as global slog logger and/or adds it to a context.

Now a library calls klog.FromContext. It would be neat if that call then returned an slogr bridge for whatever slog would be using.

Likewise with klog.NewContext: if a binary calls that and then some library uses slog, it would be good if that library would log through the Logger.

This implies that slogr has to be clue code in go-logr, and that go-logr itself needs to be built differently depending on the Go version, once slog becomes part of some release.

@pohly
Copy link
Contributor

pohly commented Apr 2, 2023

https://github.com/pohly/zapr/tree/slog has some preliminary slogr implementation.

I think the code should be in logr because then logr.SlogFromContext and logr.NewContextWithSlog become possible such that a logger set with logr.NewContextWithSlog can be retrieved with logr.FromContext and vice versa.

@thockin thockin mentioned this issue Aug 2, 2023
@pohly pohly mentioned this issue Aug 3, 2023
4 tasks
@thockin
Copy link
Contributor

thockin commented Aug 27, 2023

We now have slog support (unreleased, but should be in next tag). We'll evolve it more but I will close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants