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

Replace pulsar/log and logrus with slog #1078

Closed
flowchartsman opened this issue Aug 14, 2023 · 3 comments
Closed

Replace pulsar/log and logrus with slog #1078

flowchartsman opened this issue Aug 14, 2023 · 3 comments

Comments

@flowchartsman
Copy link
Contributor

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

pulsar/log.Logger is a pain to use since it is an interface that returns package types, thus coupling any implementation to client-pulsar-go and all of its dependencies, including logrus.

The good news is that go 1.21.0 is out, and with it comes a standard, structured logger in the stdlib: https://pkg.go.dev/log/slog Standardizing on the *slog.Logger type, would provide all of the features exercised by the current logging interface, and would future-proof the package against needing to have external logging dependencies for the foreseeable future.

Describe the solution you'd like
The entire pulsar/log package should be removed and replaced with slog integration

Additional context
There might be a way to make this change without breaking semver, but at the very least this should be a requirement before any jump to 1.0, since it will effectively end the requirement on non-stdlib logging forever.

@flowchartsman flowchartsman changed the title Replace logrus with slog Replace pulsar/log and logrus with slog Aug 14, 2023
@tisonkun
Copy link
Member

1.21.0 is out

IIRC pulsar-client-go still supports Go 1.15. What do you think of the migrating plan? As long as we declare to support versions before 1.21, we cannot fully adopt the slog solution.

Besides, how do you compare among logrus, zap and the new slog? Are they functionally different? Or just we'd prefer a solution out of the box from stdlib.

@flowchartsman
Copy link
Contributor Author

Besides, how do you compare among logrus, zap and the new slog? Are they functionally different? Or just we'd prefer a solution out of the box from stdlib.

It's less about functionality, and more about future-proofing, since there will now be standard types that can serve as a compatibility layer without forcing a non-stdlib dependency for implementation. Right now, there are some difficulties I have with the standard logger, where I'm kind of locked in to how I deal with them:

  • logs are on by default, and an explicit nop logger must be provided to disable them
  • Default logging is very chatty, but there's no option to simply set a threshold for this without another logger implementation or using the nop logger to turn it off completely
  • Package logs display in a format I don't want to use.

If I want to change any of these things, I must implement the entire interface, including more complex methods such as SubLogger, WithFields, WithField, and WithError, which return the log.Logger and log.Entry types, which means a dependency on pulsar-client-go. Or I have to use logrus with the wrapper, forcing me to have a dependency on logrus.

If the library takes a slog.Handler or a slog.Logger, I can set the threshold and formatting I want on these, and the interface is well understood and can be connected with anything that supports slog. or will in the future, since it is likely that future packages will at least have to provide a slog compatibility layer, which means easier interaction.

IIRC pulsar-client-go still supports Go 1.15. What do you think of the migrating plan? As long as we declare to support versions before 1.21, we cannot fully adopt the slog solution.

This issue has two parts: support for Go versions and semver compatibility on pulsar-client-go

As far as semver goes, change to the logging interface would have to wait for a major revision number. I don't know if there are any plans to move to 1.0 ever, but that would be the time to do it. Or if this package ever moves to major version mirroring for pulsar, that would also be an opportunity. If there is any roadmap to the next major version, I wanted to get a tracking issue here, since that should definitely be on it.

With Go versions, I think that it is okay to follow the support lifecycle of Go itself, which means two minor versions. That would currently put us at 1.20. 1.19 and older are EOL as far as Go is concerned. With the compatibility promise, it does not make much sense to declare explicit support for older versions. This at least opens up the possibility to support slog types as additional options without changing the primary logging interface once go1.21 is the oldest supported version.

RobertIndie pushed a commit that referenced this issue Jul 5, 2024
### Motivation

This commit supports to use `log/slog` package from the standard library to control the level and output type of the logs.
In order for us to not have to import logrus as a direct dependency for part of our testing suit, it would be nice if we can use `slog` package instead, and wrap that in the provided by `pulsar/log` interfaces.

This ties in a bit with issue #1078 because it opens the door for users who are already working with log/slog in their projects. Plus, it's a gives more time for the Pulsar team to evaluate incorporating slog into the SDK.

### Modifications

One additional file `/pulsar/log/wrapper_slog.go` is added.
One additional function in the `pulsar/log` package, `NewLoggerWithSlog` , is exposed.
@nodece
Copy link
Member

nodece commented Jul 25, 2024

Closed by #1234

@nodece nodece closed this as completed Jul 25, 2024
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

No branches or pull requests

3 participants