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

[observability] Replace zap with log/slog #314

Closed
2 tasks done
zalgonoise opened this issue Oct 27, 2023 · 2 comments
Closed
2 tasks done

[observability] Replace zap with log/slog #314

zalgonoise opened this issue Oct 27, 2023 · 2 comments
Labels
proposal Feature request

Comments

@zalgonoise
Copy link
Contributor

Is your feature request related to a problem? Please describe.

This is a placeholder issue to replace the current usage (and references) of uber-go/zap with standard library's log/slog package. This allows a standard logging API for any Go application, where different implementations of its slog.Handler interface focus on actually registering the log events in the appropriate backend or target output.

Note: Log levels in log/slog range from Debug to Error, so any Fatal-level log entries should be replaced with Error-level ones, followed by an os.Exit(1), if that is really the desired behavior

Describe the solution you'd like

  • The generated internal/log package contains new logic to create a log/slog logger instead of a uber-go/zap one.
  • The generated go.mod file no longer references uber-go/zap
  • All logger and logging references are replaced with log/slog equivalents

Suggestion:

  • use log/slog's Attr (slog.String, slog.Bool, etc) functions when passing attributes to log events. This keeps the key-value pairs in the attributes neatly organized, as well as leveraging the package's proposed strongly-typed attributes

Describe alternatives you've considered

N/A - the standard library inclusion means that it should be used as a common (structured) logging API for Go applications. This doesn't mean that consumers of slog are tied to it completely -- its slog.Handler interface allows custom handling of the log events, so that custom behavior is still possible by calling slog.New with a custom slog.Handler.

Search

  • I did search for other open and closed issues before opening this.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Additional context

No response

@zalgonoise zalgonoise added the proposal Feature request label Oct 27, 2023
@zalgonoise zalgonoise assigned linuxluigi and brumhard and unassigned linuxluigi and brumhard Oct 27, 2023
@zalgonoise
Copy link
Contributor Author

Closing this issue as #311 was also created just a few minutes before :D

@MarvinJWendt
Copy link
Member

You could have also closed mine, this one is way more detailed 😄
The only difference to my proposal is that I proposed to remove internal/log completely, as slog does not need a wrapper.
We could initialize the slog handler / logger directly in the entry point, I guess (just a single line of code).

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

No branches or pull requests

4 participants